c# – 实体框架指导

前端之家收集整理的这篇文章主要介绍了c# – 实体框架指导前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用sql Server 2008设置实体框架.我使用Guids作为表上的键.有没有办法设置,所以键是由数据库自动生成的?我尝试将“RowGuid”设置为true,并将列的默认值设置为“(newid())”.无论哪种方式,映射类仍然需要我在C#方面给它一个Guid.有任何想法吗?

解决方法

Not yet

17.4.Can I use a server-generated guid as my entity key?

Unfortunately,in v1 of the EF this is not supported. While it is possible with sql Server to have a column of type “uniqueidentifier” and to set it’s default value to be “newid()”,with sql Server 2000 there’s no good way to extract the value that the server generated at the time you do the insert. This can be done on more recent versions of sql Server,though,so the intent is that we should find a clean way to special case this support in future versions of the EF so it can be supported on those databases that allow it and not on others. For now,the work around is to generate the guid on the client (ideally in the constructor of your object) rather than on the server.

猜你在找的C#相关文章