Base solution for your next web application
Open Closed

Change String Max length of Name in AbpUser<TUser> #1651


User avatar
0
moustafa created

Hello Can anyone tell me the easiest way to Change String Max length of Name & Surname in AbpUser<TUser> from 32 to 100 ?


6 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can do it in OnModelCreation of your DbContext <a class="postlink" href="https://github.com/aspnetboilerplate/module-zero/issues/17">https://github.com/aspnetboilerplate/mo ... /issues/17</a>

  • User Avatar
    0
    moustafa created

    Thank you fro your help that would be the code

    [code]
    
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                base.OnModelCreating(modelBuilder);
                modelBuilder.Entity<User>().Property(t => t.Name).HasMaxLength(50);
                modelBuilder.Entity<User>().Property(t => t.Surname).HasMaxLength(50).IsOptional();
            }
    

    [/code:2jfgtrv2]

  • User Avatar
    0
    moustafa created

    Actually i succeed to change max length property as previous reply but still got an error after registration

    await _unitOfWorkManager.Current.SaveChangesAsync();
    

    Error Message Validation failed for one or more entities. See 'EntityValidationErrors' property for more details. Error Details Name: The field Name must be a string with a maximum length of 32.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    It's probably MaxLength attribute on that fields. Can you try to do it like this,

    override Name and Surname field in User entitiy.

    [MaxLength(50)]
    public override string Name { get; set; }
    
  • User Avatar
    0
    moustafa created

    i did excactly as you told me to do but unfortunately i got the same error

  • User Avatar
    0
    moustafa created

    I fount the solution

    [StringLength(50)]
            public override string Name { get; set; }
            [StringLength(50)]
            public override string Surname { get; set; }
    

    Thank you