ASP Identity table column change but mapping is not possible with new column name

asp.net-identity c# entity-framework entity-framework-6

Question

I modified the asp Identity to ensure that the databaseId a row ofAspNetIdentity desk beUserId :

modelBuilder.Entity<ApplicationUser>()
                        .Property(p => p.Id)
                        .HasColumnName("UserId");

And it's effective. Produced tables haveUserId instead Id .
I now have a different table that needs to be mapped withAspNetUsers by UserId :
Write it like this:

public class JobApply
    {   ...
        public int UserId { get; set; }       
        public virtual ApplicationUser ApplicationUser { get; set; }

A database table looks like this:
enter image description here
And if I put it this way:

public class JobApply
    {   ...
        public int ApplicationUserId { get; set; }
        public virtual ApplicationUser ApplicationUser { get; set; }

database appearance:
enter image description here


first created optionUserId although it is not a fieldFK rather than that, a new field is included asFK .
What should I do to appropriately map this to a table?JobApply using fieldUserId to beFK to AspNetUsers ?

UPDATE

I'll also say this:

base.OnModelCreating(modelBuilder);

            modelBuilder.Entity<ApplicationUser>()
                        .Property(p => p.Id)
                        .HasColumnName("UserId");

            modelBuilder.Entity<JobApply>()
                    .HasRequired(e => e.ApplicationUser)
                    .WithMany()
                    .HasForeignKey(e => e.UserId);

Tables are related as follows:
enter image description here
Both classes include this:

public class ApplicationUser : IdentityUser<int, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
    {
        public string Email { get; set; }
        public string ConfirmationToken { get; set; }
        public bool IsConfirmed { get; set; }
        public string PasswordResetToken { get; set; }

        public int CityId { get; set; }
        public virtual City City { get; set; }


        public virtual ICollection<JobApply> JobApplies { get; set; }
    }

public class JobApply
    {
        public int JobApplyId { get; set; }
        public int UserId { get; set; }
        public int JobId { get; set; }
        public int JobApplyStatusId { get; set; }
        public DateTime CreatedDate { get; set; }

        public virtual ApplicationUser ApplicationUser { get; set; }
        public virtual Job Job { get; set; }
        public virtual JobApplyStatus JobApplyStatus { get; set; }

    }
1
1
6/29/2014 11:34:58 AM

Accepted Answer

ZZZ_tmp
2
5/3/2015 7:46:12 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