I have a standard Identity
user in my app...
public class ApplicationUser : IdentityUser<int, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
{...
...Which has Id
as primary key.
How can I change Id
to UserId?
I ask this because I have table that should be connected with AspNetUsers
table.
And I did it like this:
public class ApplicationUser : IdentityUser<int, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
{...
public virtual ICollection<JobApply> JobApplies { get; set; }
And JobApply
code is:
public class JobApply
{...
public int ApplicationUserId { get; set; }
public virtual ApplicationUser ApplicationUser { get; set; }
The result of this is this:
I want to make this better somehow.
I want to have UserId
instead Id
so columns in both table to be names UserId.
Is there a way to do this?
You can't change the name. Id is defined at the very bottom of the extension system in IUser<T>
, which all IdentityUser
implementations must ultimately inherit from.
Just no way to do it without rewriting everything.
You COULD change the name of the field as it's stored in the database, but you can't change the name of the property as used in code. If you only want to change the name of the column in the database, then you need only use FluentConfiguration to change the name of the property.
EDIT:
In your ApplicationContext you would do this:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ApplicationUser>()
.Property(p => p.Id)
.HasColumnName("UserId");
}