Autogenerate ID GUID Entity Framework Data Type

I looked at this post and tried to do it this way

Primary Auto Generation Key (Guid) Entity Framework CTP5

[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid CompanyID { set; get; } 

However, I still get the error message

 Identity column 'CompanyID' must be of data type int, bigint, smallint, tinyint, or decimal or numeric with a scale of 0, and constrained to be nonnullable. 

This is when I run the "Update Database" command in the package manager console.

+5
source share
1 answer

It had the same problem, the only thing that helped me: reset the database to its initial empty state, delete all migrations and create a new one with the corresponding GUID:

  • Update-Database -TargetMigration:0
  • Delete all migrations
  • Add-Migration InitialCreate
  • Update-Database

I agree that this is not the best solution, but it was acceptable for me, since I started the project a few hours before.

+3
source

All Articles