This project is read-only.

Guid Primary Keys?

Aug 5, 2010 at 4:38 PM
Are Guid Primary Keys supported? In my first test project with nHydrate I created a simple Contact which uses a Guid PK, but when I use the Installer project to create the DB, I get a popup Sp Fail: <company>.<project>.Install.Stored_Procedures.Generated.Objects.Contacts.sql. Then the Debugger stops in UpgradeInstaller.cs with a SqlException "Operand data type uniqueidentifer invalid for max operator" caught on line 37 inside the UpgradeDatabase method. Inside the model for the Contacts table, I set the Id column Data Type = uniqueidentifier, Primary Key = true, Identity = Code. The problem seems to be inside the gen_ContactsInsert stored procedure: Set @Id = (select case when max([Id]) is null then 1 else max([Id]) + 1 end from Contacts) Since Identity is set to Code, is this line even required? Since I absolutely require Guid PKs, I wanted to verify that Guid PKs are supposed to be supported before investing anymore time? Or do I simply have the model misconfigured somehow? Thanks.
Aug 5, 2010 at 11:57 PM

Please send your model to

Aug 6, 2010 at 3:09 AM

I see now what you mean. The Identity was wrong. This was an oversight. The next version will only allow identity settings for Int, SmallInt, and BigInt. Sorry about this. Please turn this off in your model for a Guid key to work.

Aug 6, 2010 at 3:37 PM

Thanks, for the quick response!  That did the trick.