问题描述
我正在用EF4做一点测试,我试图建立一个主键是一个Guid的实体,
Hi, I am doing a little test with EF4, and I've tried to set up one entity which the primary key is one Guid,
直到这一点,每件事都没问题!但是当试图插入数据库时,视觉工作室抛出一个错误,说该对象无法保存,因为Id(那个´ s我的主键)为null,否则EF不会生成一个Guid for Id!
Till this point, every thing is ok!, but whene try to insert into database, the visual studio throw one error saying that the object can't be saved because the Id (that´s my primary key) is null, otherwise the EF don't genarate one Guid for Id!
我能做些什么来解决我的问题?
What can I do to solve my problem?
谢谢。
Gabriel Oliveira。
Gabriel Oliveira.
推荐答案
是否在自动生成GUID主键列数据库方面? 请在GUID PK属性上将
StoreGeneratedPatterns 设置为身份。 有关详细信息,请参阅
http://blogs.msdn.com/alexj/archive/2009/05/20/tip-19-how-to-use-optimistic-concurrency-in-the -entity-framework.aspx 功能;&安培;
。
Is the GUID primary key column auto-generated at the database side? Please set theStoreGeneratedPatterns to Identity on the GUID PK property. For detail, please seehttp://blogs.msdn.com/alexj/archive/2009/05/20/tip-19-how-to-use-optimistic-concurrency-in-the-entity-framework.aspx &http://msdn.microsoft.com/en-us/library/dd283139.aspx.
谢谢你
Lingzhi Sun
Thanks
Lingzhi Sun
这篇关于Guid作为实体框架上的PrimaryKey的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!