加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 实体框架指导

发布时间:2020-12-15 06:36:55 所属栏目:百科 来源:网络整理
导读:我正在尝试使用SQL Server 2008设置实体框架.我使用Guids作为表上的键.有没有办法设置,所以键是由数据库自动生成的?我尝试将“RowGuid”设置为true,并将列的默认值设置为“(newid())”.无论哪种方式,映射类仍然需要我在C#方面给它一个Guid.有任何想法吗?
我正在尝试使用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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读