How do I change the name of the ASPNETUsers table to User?

asp.net-core entity-framework entity-framework-core

Question

I am using the default authentication system created by ASP.NET Core, and I'd like to know ?

  1. how to change the name of the ASPNETUsers table to User ?

  2. How to add the following property to the table: public string DisplayName {get; set;}

  3. How to add the RemoteAttribute attribute to the Email property

  4. Is it a good idea to create another table, named Profile, with a one-to-one relationship with the ASPNETUsers table, if I have a few properties ?

thanks...

1
3
9/23/2016 7:12:07 AM

Accepted Answer

You can do those as shown below.

1.

  protected override void OnModelCreating(ModelBuilder builder)
   {
       base.OnModelCreating(builder);

       builder.Entity<ApplicationUser>(entity =>
          {
              entity.ToTable(name:"User");
           });
   }

2.

public class ApplicationUser : IdentityUser
{
    ......................
    ......................
    public string DisplayName {get; set;}
}

3. I would like to suggest you to put that on your ViewModel instead of the Core model (i.e. ApplicationUser ) as shown below.

using Microsoft.AspNet.Mvc;
using System.ComponentModel.DataAnnotations;

public class LoginViewModel
{
    [Required]
    [EmailAddress]
    [Remote("Foo", "Home", ErrorMessage = "Remote validation is working for you")]
    public string Email { get; set; }


}

4. Hence you have only few properties,you can keep those properties inside the ASPNETUsers table itself. Which is easy to maintain :)

3
9/23/2016 8:01:44 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow