实体框架4主键作为GUID和自动生成 [英] Entity Framework 4 Primary Key as GUID and autogeneration

查看:130
本文介绍了实体框架4主键作为GUID和自动生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用EF4,以及让GUID生成服务器端的新功能。我有一个带有GUID主键的表,其默认值在SQL Server中设置为NewID()。但是,我已经尝试将StoreGeneratedPattern设置为Identity和Computer,并且都不起作用。我在MSDN上发现了这个链接,有冲突的信息。有人说它应该工作,有些不会。

I'm trying to use EF4 and the supposedly new feature of having GUIDs generated server side. I have a table with a GUID primary key and its default value is set to NewID() in SQL Server. However, I have tried setting StoreGeneratedPattern to Identity and Computer and neither works. I found this link on MSDN, with conflicting information. Some say it should work, some don't.

http://social.msdn.microsoft.com/Forums/en/adonetefx/thread/72f0045d-1619-4044-bf50-c6eb5091995e

任何人都可以确认这是否应该或不应该工作?

Can anyone confirm if this should or should not work?

推荐答案

如果您设置 StoreGeneratedPattern 。它在3.5中不起作用。 无效率索引注释只有在GUID PK上有聚簇索引时才是真实的。如果您的群集索引在别处,则为false。

It does work in 4.0 if you set StoreGeneratedPattern. It does not work in 3.5. The "inefficient indexing" comment is only true if you have a clustered index on the GUID PK. It's false if your clustered index is elsewhere.

这篇关于实体框架4主键作为GUID和自动生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆