生成实体密钥
我第一次对 Entity Framework 4 感到失望。事实证明,SQL CE 与 EF4 一起使用时,不支持自动生成主键。我从 OnjectContext.SaveChanges() 收到 System.Data.UpdateException 并显示以下消息:
SQL Server Compact 不支持服务器生成的键和服务器生成的值。
因此,现在我必须手动生成我的实体的密钥。假设我想使用自动递增整数键,那么在使用实体框架时生成和跟踪键的最佳方法是什么?感谢您的帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您问题的链接底部是建议的解决方案。请参阅 SQL Compact、Identity Columns 和 Entity Framework 也许您可能会想要实现一种像概述的那样的扩展方法。
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.
我不认为大卫的想法是个好主意,但是,我别无选择。
也许CE会在下一个版本中支持自动生成的主键。
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.