Entity Generation

I came across my first disappointment with Entity Framework 4. It turns out that SQL CE when used with EF4 does not support automatically generated primary keys . I get a System.Data.UpdateException message from OnjectContext.SaveChanges () with this message:

Server keys and server-generated values ​​are not supported by SQL Server Compact.

So, now I need to manually generate keys for my objects. Assuming I want to use automatic incremental integer keys, what is the best way to generate and track keys when using Entity Framework? Thank you for your help.

+3
source share
2 answers

At the bottom of the link, your question suggests a suggested solution. See SQL Compact, Identity Columns, and Entity Framework ; you may need to implement an extension method similar to that described.

+4
source

I don’t think David’s idea is a good idea, but I have no choice. Perhaps CE will support automatically generated primary keys in a future version.

0
source

Source: https://habr.com/ru/post/1304602/


All Articles