Question

I have run into my first dissapointment with Entity Framework 4. It turns out that SQL CE, when used with EF4, does not support autogenerated primary keys. I get a System.Data.UpdateException from OnjectContext.SaveChanges() with this message:

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

So, now I have to manually generate keys for my entities. Assuming I want to use auto-incremented integer keys, what is the best way to go about generating and keeping track of the keys when using Entity Framework? Thanks for your help.

Was it helpful?

Solution

At the bottom of the link in your question is a suggested solution. See SQL Compact, Identity Columns and Entity Framework perhaps you might want to implement an extension method like the one outlined.

OTHER TIPS

I don't think David's idea is a good idea, however, I have no choice. Maybe CE will support autogenerated primary keys in next version.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top