Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework with ROWGUIDCOL

I have a table with a non-PK rowguidcol column like this:

CREATE TABLE [dbo].[SomeTable] (
  ...
  RowGuid uniqueidentifier NOT NULL DEFAULT (NEWSEQUENTIALID()) ROWGUIDCOL,
  ...
  CONSTRAINT AK_SOMETABLE_ROWGUID UNIQUE (RowGuid)
  ...
 )

When I try to add a record through EF (version 4.3.1), the following exception is raised:

Violation of UNIQUE KEY constraint 'AK_SOMETABLE_ROWGUID'. Cannot insert duplicate key in object 'dbo.SomeTable'.
The duplicate key value is (00000000-0000-0000-0000-000000000000).

I am leaving the RowGuid field as null. But it seems EF is zeroing out the guid column value.

How do I tell EF that the new row should be populated by NEWSEQUENTIALID() at server level?

like image 783
invarbrass Avatar asked Dec 28 '25 20:12

invarbrass


1 Answers

Update: After reading this blog post, I set the StoreGeneratedPattern property to "Identity" in the EDM designer. It seems to be working now.

like image 151
invarbrass Avatar answered Dec 31 '25 14:12

invarbrass



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!