gpt4 book ai didi

entity-framework - ASP.NET-Identity:如何限制用户名长度?

转载 作者:行者123 更新时间:2023-12-04 08:25:39 24 4
gpt4 key购买 nike

如何限制 UserName 的长度表中的字段AspNetUsers ?
既不是这个:

public class ApplicationUser : IdentityUser
{
[Required, MaxLength(15)]
public string UserName { get; set; }

}
或这个: modelBuilder.Entity<ApplicationUser>().Property(x => x.UserName).HasMaxLength(15);作品。
我需要这个,因为设置了 Indexnvarchar(max) 上给我这个错误信息:

Column 'UserName' in table 'dbo.AspNetUsers' is of a type that isinvalid for use as a key column in an index.


详细地说,我试图像这样设置索引:
public override void Up()
{
CreateIndex("dbo.AspNetUsers", "UserName", true, "IX_UserName");
}

public override void Down()
{
DropIndex("dbo.AspNetUsers", "IX_UserName");
}

最佳答案

在今天发布的最新版本中,这应该可以解决问题:
modelBuilder.Entity<ApplicationUser>().Property(x => x.UserName).HasMaxLength(15);

关于entity-framework - ASP.NET-Identity:如何限制用户名长度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21975717/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com