I have a simple table with an ID (a uniqueidentifier
), a datetime
, and a value.
I'd like to use getdate()
on the database for the record insertion time and newid()
for the id. How do I configure entity framework to do this? When I try to assign the id on the DB I get:
Violation of PRIMARY KEY constraint 'PK_Random'. Cannot insert duplicate key in object 'dbo.Random'. The duplicate key value is (00000000-0000-0000-0000-000000000000).
Just to add to this since @lunateck answer helped me. The other way (if you are using Database First) is to:
edmx
file.StoreGeneratedPattern
to Identity
.if you are using code first. Please add the following to your guid.
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid guId { get; set; }
This will enable sql server side guid generation. Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With