문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top