So, I have my User
that inherits IdentityUser
.
However, I want to set the minimum length of the UserName
to be 5
and the maximum length to be 30
.
I tried this
public class User : IdentityUser
{
[Required]
[StringLength(nameMaxLength, MinimumLength = nameMinLength)]
public string UserName { get; set; }
public IEnumerable<UserMovie> UsersMovies { get; set; }
}
but it did not work. I found that I could probably set the max length via FluentAPI like this
protected override void OnModelCreating(ModelBuilder builder)
{
builder
.Entity<User>()
.Property(x => x.UserName)
.HasMaxLength(15);
base.OnModelCreating(builder);
}
but nothing for the minimum length.