msallin / SQLiteCodeFirst

Creates a SQLite Database based on a EdmModel by using Entity Framework CodeFirst.
Apache License 2.0
608 stars 123 forks source link

[DatabaseGenerated(DatabaseGeneratedOption.Identity)] for Guid #147

Closed Schwenkner closed 4 years ago

Schwenkner commented 4 years ago

May be I have overseen something.

I want to use a Guid as the primary key. Pls no discussion upon it is better not to use. We have to replicate the database with others, so an integer key cannot guranty not to be duplicated.

I have to decorate the key with

[DatabaseGenerated(DatabaseGeneratedOption.Identity)]

as I read, if I want SQLite to return the newly generated key. But therefor the key column must have the attribute NOT NULL, otherwise I'm getting an exception. How can I acheave this? In the code I have seen, that in "AddNullConstraintIfNecessary" a "NotNullConstraint" will not be generated, if the property is an identity property. But here I need it.

msallin commented 4 years ago

Does SQLite support the auto creation of new GUID primary keys?

Please provide the DDL SQL which results in the behavior you would like to get.

msallin commented 4 years ago

Closed due to inactivity. Feel free to reopen.