Support GUID as Entity Key
This should be supported in the designer.
http://leedumond.com/blog/using-a-guid-as-an-entitykey-in-entity-framework-4/
12 comments
-
Justin
commented
mabster, I don't agree that EF should ensure that we don't create a clustered index. An orm should never didicate database design. Plus clustered index performance is just fine as long as you use NEWSEQUENTIALID(). That's the whole point of that function.
GUIDs sometimes have to be a primary key. A perfect example is a WPF client app with offline access and peer-to-peer sync which we are building now.
-
Ricardo Peres
commented
A more general request: Extensible Id Generation (http://data.uservoice.com/forums/72025-ado-net-entity-framework-ef-feature-suggestions/suggestions/1796337-extensible-id-generation)
-
HiredMind
commented
@Kram: Google "KB2561001". It's fixed! :-) (At least for DB-First, or non-Guid keys)
-
Kram
commented
Another glitch which, until fixed, makes EF unusable for us. We will consider putting EF into production apps when we no longer have to continually hack the edmx file, like manually re-adding the StoreGeneratedPattern="Identity" for GUID key fields every time the EDM is updated from the database.
-
mabster
commented
GUIDs as primary keys are fine provided it's a non-clustered index. Baked in support for GUID keys should ensure that they don't create a clustered index when creating the table.
-
Paul Barton commented
Just something like guid.comb from NH would be perfect!
-
Mohammed Hasan
commented
GUID not being supported 100% in the Designer is a major bug/flaw in Entity Framework 4.0 considering Microsoft itself uses GUID's as primary keys in as rudimentory framework as the SqlMembershipProvider in asp.net. Using GUID's as primary keys is a generally accepted database methodology. What were you guys thinking or not thinking? Instead of including this in the next version of the framework how about a service release to fix this problem. Manually editing the SSDL section everytime we work on a existing database model with Guid's is getting to be a major pain.
-
Anonymous
commented
A guid should never be the primary key of MS sql server table.
-
mike
commented
Yes! BUT please make sure they are sequential by date/time when generated!
-
Kristofer Andersson
commented
@Matthieu - FYI: I have a workaround for that in my add-in's "model comparer" feature for EF4. It allows you to choose what default constraints (e.g. newid, newsequentialid) should be treated as storegeneratedpattern=identity and which default constraints should be treated as storegeneratedpattern=computed. See http://huagati.blogspot.com/2010/08/whats-new-in-model-comparer-for-entity.html
-
Matthieu MEZIL commented
It's the same with Computed columns
And it's a big problem, particularly with this f... designer which lose all SSDL modification when I update my model from DB. -
Matthieu MEZIL commented
+1.
In my opinion, only the StoreGeneratedPattern in CSDL should be used.