如何限制表AspNetUsers中的UserName字段?
这不是:
public class ApplicationUser : IdentityUser { [required,MaxLength(15)] public string UserName { get; set; } }
或这个:
modelBuilder.Entity< ApplicationUser>().Property(x => x.UserName).HasMaxLength(15);
作品.
我需要这个,因为在nvarchar(max)上设置索引会给我这个错误消息:
Column ‘UserName’ in table ‘dbo.AspNetUsers’ is of a type that is
invalid 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);