entity-framework – ASP.NET-Identity限制UserName长度

如何限制表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);

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....