问题描述
我已经遇到了我对Entity Framework 4的第一次失望。事实证明SQL CE与EF4一起使用时,。我从OnjectContext.SaveChanges()获取一个System.Data.UpdateException,并显示以下消息:
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:
SQL不支持服务器生成的密钥和服务器生成的值服务器紧凑。
所以现在我必须为我的实体手动生成密钥。假设我想使用自动递增的整数键,使用实体框架时最好的方式来生成和跟踪键?感谢您的帮助。
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.
这篇关于生成实体密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!