我想设置如下。
我正在使用代码优先方法的最新 Entity Framework ..
Public class AppUser
{
[Key]
public int Id { get; set; }
[Required]
[Index(IsUnique = true)]
public string UserName { get; set; }
}
但是它不起作用..
示例记录如下
收到以下错误信息:
"exceptionmessage": "Column 'UserName' in table 'dbo.ApplicationUser' is of a type that is invalid for use as a key column in an index.",
最佳答案
您需要限制UserName
属性的长度。为此使用 StringLength
注释。
If the size of all fixed key columns plus the minimum size of all variable columns specified in the CREATE INDEX statement exceeds 900 bytes, the CREATE INDEX statement fails.
关于c# - 如何在实体中的使用表中创建 PK 和唯一用户名(使用代码优先)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45386800/