ASP.NET-Identity限制UserName长度 [英] ASP.NET-Identity limit UserName length
本文介绍了ASP.NET-Identity限制UserName长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何限制 UserName
字段在表 AspNetUsers
?
这不是:
public class ApplicationUser : IdentityUser
{
[Required, MaxLength(15)]
public string UserName { get; set; }
}
或此:
modelBuilder.Entity< ApplicationUser>()。Property(x => x.UserName).HasMaxLength(15);
工作。
我需要这个,因为设置索引
code> nvarchar(max)给我这个错误msg:
I need this because setting an Index
on an nvarchar(max)
gives me this error msg:
表中的UserName 'dbo.AspNetUsers'的类型是
无效,用作索引中的关键列。
Column 'UserName' in table 'dbo.AspNetUsers' is of a type that is invalid for use as a key column in an index.
要详细,我试图设置这样的索引:
To be verbose, I was trying to set the indexes like this:
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);
这篇关于ASP.NET-Identity限制UserName长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文