SaveChanges using GUID as EntityKey in Entity Framework

entity-framework guid

Question

I have a database table in SQL Server 2008 that utilizes uniqueidentifier as its primary key. The newid() method on the database side is used to produce the key for inserts.

ADO.NET has no issues with this. However, there is a difficulty when I put up this table as an entity in an Entity Framework 4 model. I have no trouble querying the entity, but when I create a new entity and call SaveChanges() on the context, the database's created unique identifier contains just zeros.

I know that EF v1 had a bug that prevented this situation from working, necessitating the creation of the GUID on the client before invoking SaveChanges. But I had read several times that they intended to address issue with EF 4.

I want to know whether EF4 still does not enable this case (DB-side creation of uniqueidentifier). Do we have to continue creating the GUID on the client?

1
9
5/13/2010 1:37:41 PM

Accepted Answer

6
7/12/2014 12:35:33 AM

Popular Answer

Yes, this was changed in EF 4. @MusiGenesis, server-generated GUIDs may be consecutive, for example, which is one benefit.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow