primary-key

ORM support for compound primary keys

血红的双手。 提交于 2019-12-18 09:25:51
问题 I've read that compound primary keys will confuse the hell out of typical ORM code generators. Which ORMs work best with compound PKs and which to avoid? (I've a particular interest in .NET) 回答1: I'm using NHibernate successfully with compound keys. <class name="UserProfileField" table="UserProfileFields"> <composite-id> <key-many-to-one name="Parent" column="UserId" lazy="false"/> <key-property name="FieldName"/> </composite-id> ... 来源: https://stackoverflow.com/questions/218100/orm-support

ORM support for compound primary keys

 ̄綄美尐妖づ 提交于 2019-12-18 09:25:18
问题 I've read that compound primary keys will confuse the hell out of typical ORM code generators. Which ORMs work best with compound PKs and which to avoid? (I've a particular interest in .NET) 回答1: I'm using NHibernate successfully with compound keys. <class name="UserProfileField" table="UserProfileFields"> <composite-id> <key-many-to-one name="Parent" column="UserId" lazy="false"/> <key-property name="FieldName"/> </composite-id> ... 来源: https://stackoverflow.com/questions/218100/orm-support

Proposal: locally unique GUID alternative

安稳与你 提交于 2019-12-18 09:10:13
问题 The problem I'm looking for feedback on this exploration of a locally unique alternative for GUIDs , with the following requirements: Has very low chance of collisions (to the point that we'd rather collide once a year than perform checks) Does not leak sensitive information, such as how many items exist Has high performance in an SQL database Is copy/pastable for manual querying (as both query string and query result) Is usable as a URI component without encoding To meet the requirements, I

ObjectContext.SaveChanges() violates primary key, throws UpdateException?

非 Y 不嫁゛ 提交于 2019-12-18 07:09:31
问题 Paraphrasing from this MSDN documentation ... An INSERT statement is generated by the Entity Framework and executed on the data source when SaveChanges is called on the ObjectContext. If the INSERT operation succeeds, server-generated values are written back to the ObjectStateEntry. When AcceptChanges is called automatically at the end of the SaveChanges execution, a permanent EntityKey is computed by using the new server-generated values. This does not seem to be occurring in my code. When I

How to determine the primary key for a table in SQL Server?

£可爱£侵袭症+ 提交于 2019-12-18 03:44:24
问题 What I'd like to be able to do in SQL Server 2005 somehow is with a table name as input determine all the fields that make up the primary key. sp_columns doesn't seem to have this field. Any ideas as to where to look? 回答1: I use this in a code generator I wrote to get the primary key: SELECT i.name AS IndexName, OBJECT_NAME(ic.OBJECT_ID) AS TableName, COL_NAME(ic.OBJECT_ID,ic.column_id) AS ColumnName, c.is_identity, c.user_type_id, CAST(c.max_length AS int) AS max_length, CAST(c.precision AS

Hibernate & postgreSQL with Grails

帅比萌擦擦* 提交于 2019-12-18 02:54:33
问题 There is an easy way to set hibernate to use different primary key ids for each table with postgres? I tried to use postgres dialect in DataSource: dialect = org.hibernate.dialect.PostgreSQLDialect or dialect = net.sf.hibernate.dialect.PostgreSQLDialect But it doesn't work. Thanks 回答1: The short answer is no, there isn't a easy way to do this. However, I have found a solution that does work. Basically you need to implement a custom dialect. Here is an implementation (please note the original

Can we use Guid as a Primary Key in Sqlite Database

被刻印的时光 ゝ 提交于 2019-12-17 22:18:37
问题 Is is possible to use GUID as primary Keys in SQLITE Database?If Possible which datatype can be used? 回答1: SQLite itself does not support GUID as internal type. Except that, it does! (sort of). Remember, in SQLite any string can be used as type name, and that includes GUID or UUID (read more about SQLite datatypes). According to those rules, GUID type has affinity NONE , which is the same as for BLOB fields. With this in mind, you can create column of GUID type, and use following rules to

Can a foreign key refer to a primary key in the same table?

邮差的信 提交于 2019-12-17 22:17:16
问题 I just think that the answer is false because the foreign key doesn't have uniqueness property. But some people said that it can be in case of self joining the table. I am new to SQL . If its true please explain how and why? Employee table | e_id | e_name | e_sala | d_id | |---- |------- |----- |--------| | 1 | Tom | 50K | A | | 2 | Billy | 15K | A | | 3 | Bucky | 15K | B | department table | d_id | d_name | |---- |------- | | A | XXX | | B | YYY | Now, d_id is foreign key so how it can be a

how to set the primary key when writing a pandas dataframe to a sqlite database table using df.to_sql

旧城冷巷雨未停 提交于 2019-12-17 18:55:43
问题 I have created a sqlite database using pandas df.to_sql however accessing it seems considerably slower than just reading in the 500mb csv file. I need to: set the primary key for each table using the df.to_sql method tell the sqlite database what datatype each of the columns in my 3.dataframe are? - can I pass a list like [integer,integer,text,text] code.... (format code button not working) if ext == ".csv": df = pd.read_csv("/Users/data/" +filename) columns = df.columns columns = [i.replace(

Why is the foreign key part of the primary key in an identifying relationship?

断了今生、忘了曾经 提交于 2019-12-17 18:39:29
问题 I'm trying to understand a concept rather than fixing a piece of code that won't work. I'll take a general example of a form (parent table) and a form field (child table). Logically , this would be an identifying relationship, since a form field cannot exist without a form. This would make me think that in order to translate the logical relationship into the technical relationship, a simple NOT NULL for the form_id field in the form_field table would suffice. (See the left part of above