1

I have changed the type of primary key of IdentityUser class from string to int following this.

Now when I go to insert data in User table, it wants data for Id field. But I want that the value in Id field will be automatically created by Identity.

In server explorer when I open table definition, it shows

[Id] INT NOT NULL

but I think it should be

[Id] INT IDENTITY(1,1) NOT NULL

So what should I do to make

[Id] INT IDENTITY(1,1) NOT NULL
Jobayer Ahmmed
  • 1,856
  • 3
  • 16
  • 20
  • 1
    See http://stackoverflow.com/questions/1049210/adding-an-identity-to-an-existing-column – VDWWD Oct 09 '16 at 11:53

1 Answers1

1

You need to add DatabaseGenerated(DatabaseGeneratedOption.Identity) attribute on your Id field:

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

and then add an EF migration - it will change the ID field to be auto-incremented.

trailmax
  • 34,305
  • 22
  • 140
  • 234