Search code examples
asp.net-mvcentity-frameworkoptimizationasp.net-identity

Why in Asp.Net Identity 2.0 PhoneNumber is [nvarchar](max)


I am using Asp.Net Identity 2.0 in my MVC 5 project.

Why is column PhoneNumber using [nvarchar](max) in SQL Server database table [dbo].[AspNetUsers]?

Can I change this to [nvarchar](64), for example?


Solution

  • I created a class ApplicationUser : IdentityUser in which I override property PhoneNumber with attribute [MaxLength(64)].

    public class ApplicationUser : IdentityUser
    {
        [MaxLength(64)]
        public override string PhoneNumber { get; set; }
    
        public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
        {
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
            return userIdentity;
        }
    }