ASP.NET-Identity limit UserName length?

Feb 27, 2014 at 5:24 PM
How can I limit the UserName field in the table AspNetUsers?

Neither this:
public class ApplicationUser : IdentityUser
{
    [Required, MaxLength(15)]
    public string UserName { get; set; }
}
or this:
modelBuilder.Entity<ApplicationUser>().Property(x => x.UserName).HasMaxLength(15);
works.

I need this because setting an Index on a "nvarchar(max)" gives me this error msg:
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");
}
Developer
Mar 6, 2014 at 9:18 PM
@Yustme: This is fixed for 2.0.0. The username is limited to 256 characters and is made an index. Hope this solves the issue
Mar 6, 2014 at 9:22 PM
Hi,

Alright, any idea if I can limit it even further with fluent api or maxlength attribute?
And when will 2.0.0 be released? I don't see it appear yet in the nuget.
Developer
Mar 7, 2014 at 6:43 PM
The 2.0.0-beta1 is already on nuget and
     var entity = modelBuilder.Entity<ApplicationUser>();
        entity.Property(x => x.UserName).HasMaxLength(50);
works on those bits.
Mar 7, 2014 at 10:23 PM
Beta... aiight, guess ill wait for the final. good to know I can limit it even further with the modelbuilder like in my first post.
Mar 17, 2014 at 11:48 AM
Edited Mar 17, 2014 at 11:49 AM
@Yustme: I tried to set the UserName as my custom Firstname + Lastname properties. It sets it ok. But when I try to log in fails. Is this because the password is hashed using the email as salt? any way I can override this to still use the email as hash at login time but use the username as username?

Sorry I know I should have started a new question. I apologise.