How to use guid as primary key column (identifier) ​​in entity 5 infrastructure with default value newid ()?

I am using Entity Framework 5.0 on "Model First". There is an error in 4.x: the constructor cannot process the primary guid column with the identifier and defaultValue: "newid ()" (source: http://leedumond.com/blog/using-a-guid-as-an-entitykey-in -entity-framework-4 / )

Is it impossible to use this in EF5? What is the problem of converting C # guid to sql "uniqueid"?

+4
source share
1 answer

This worked for me, making the database first, but may help you after creating your database -

You can update the table and set the default value as newid() using Server Management Studio (not through EF).

Then, in the EF model, upgrade StoreGeneratedPattern from none to Identity .

2013 edit: For completeness, in EF 5.0 Codefirst you can specify the following data annotations:

 [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public Guid TableIdColumn { get; set; } 
+9
source

Source: https://habr.com/ru/post/1433607/


All Articles