views:

43

answers:

1

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?

A: 

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.

Craig Stuntz
So should you set StoreGeneratedPattern to Computed or Identity? Still no luck, works fine on Identity Int and BigInt fields, but draws a blank on any UniqueIdentifier fields.
AKoran
Identity. Did you change the SSDL? See this post: http://leedumond.com/blog/using-a-guid-as-an-entitykey-in-entity-framework-4/
Craig Stuntz
Yes, I see, so in effect it doesn't really work using only the designer. The other downside is you have to always remember to put the StoreGeneratedPattern back in after refreshing the model from the DB. Not the most excellent solution! However, neither of those are your fault. Thank you for pointing me in the correct direction.
AKoran