question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make Surname not required in my User class

See original GitHub issue

Hi,

I changed my User class and my AbpUsers table to not require Surname:

User.cs:

public class User : AbpUser<User>
    {
        public static string CreateRandomPassword()
        {
            return Guid.NewGuid().ToString("N").Truncate(16);
        }

        public static User CreateTenantAdminUser(int tenantId, string emailAddress, string password)
        {
            return new User
            {
                TenantId = tenantId,
                UserName = AdminUserName,
                Name = AdminUserName,
                Surname = AdminUserName,
                EmailAddress = emailAddress,
                Password = new PasswordHasher().HashPassword(password)
            };
        }

        /// <summary>Surname of the user.</summary>
        [StringLength(32)]
        public override string Surname { get; set; }
    }

But when I try save a new user without a Surname a DbEntityValidationException is thrown.

What can I do to make this property not required?

Abp version: 10.3.0

Thanks

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
fupandacommented, Mar 2, 2018

I know it’s an old thread, but had also troubles on this one. Couldn’t get it to work.

@acjh , finally I used your solution. And added some code in the UserManager in order to make it always work

public override Task<IdentityResult> CreateAsync(User user)
 {            
      user.Name = user.Name ?? String.Empty;
      user.Surname = user.Surname ?? String.Empty;
      return base.CreateAsync(user);
 }
0reactions
acjhcommented, Mar 2, 2018

That’s great 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Making first name, last name a required attribute rather ...
I'm trying to make sure that the first name and last name field are not optional for the auth User model but I'm...
Read more >
What should one fill in the last name column (mandatory) if ...
One person I know who is mononymous (who has only one name, not a given name + a family name), said this when...
Read more >
What should the character limit(s) for first/last name inputs ...
In theory the correct answer is no upper limit for name lengths. Allow the user to enter whatever their name is using whatever...
Read more >
Name and Surname optional #321
Hello, is it possible to set the User.Name and User.Surname as optional? How can I achieve this? Currently both are marked as Required....
Read more >
User.first_name - The Admin
I want to now retrieve the first and/or last name. Not sure if I need to assign the name to a variable, if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found