How to tell the primary key 'Id' of IdentityUser class is IDENTITY(1,1)?

梦想与她 提交于 2020-01-15 09:08:25

问题


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

回答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.



来源:https://stackoverflow.com/questions/39940228/how-to-tell-the-primary-key-id-of-identityuser-class-is-identity1-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!