【问题标题】:How to tell the primary key 'Id' of IdentityUser class is IDENTITY(1,1)?如何判断 IdentityUser 类的主键“Id”是 IDENTITY(1,1)?
【发布时间】:2016-10-10 04:48:19
【问题描述】:

this之后,我已将 IdentityUser 类的主键类型从 string 更改为 int。

现在,当我在 User 表中插入数据时,它需要 Id 字段的数据。但我希望Id字段中的值将由Identity自动创建。

在服务器资源管理器中,当我打开表定义时,它会显示

[Id] INT NOT NULL

但我认为应该是

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

那我该怎么做

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

【问题讨论】:

标签: asp.net asp.net-identity


【解决方案1】:

您需要在Id 字段中添加DatabaseGenerated(DatabaseGeneratedOption.Identity) 属性:

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

然后添加一个 EF 迁移 - 它会将 ID 字段更改为自动递增。

【讨论】:

    猜你喜欢
    • 2012-07-11
    • 2015-06-08
    • 2015-07-30
    • 2010-12-05
    • 2012-03-16
    • 2011-10-28
    • 1970-01-01
    • 2013-10-02
    • 1970-01-01
    相关资源
    最近更新 更多