brika28
brika28

Reputation: 65

Creating a relation with ASPNetUsers table and custom

Im trying to make a relation with ASPNETUsers table and my custom table. ASPNetUsers will contain users who register and then Admin can chose from the list of Users and pick a User which will then become a employee. I didnt implement any logic to that yet because I dont know how to connect those tables. Im not looking for done code I just cant figure out how to connect this two.

This is te structure of my DB

This is my soluton structure

On photos above you can see my DB and solution structure. AlgebraSchoolApp is MVC app with individual users accounts login. Entities contatin my models which are added in ApplicationDbContext inside AlgebraSchoolApp. DAL is just used for accesing data from DB (update,edit,delete functions).

Upvotes: 2

Views: 2023

Answers (1)

Jerdine Sabio
Jerdine Sabio

Reputation: 6140

Open IdentityModels.cs located at ProjectName > Models > IdentityModels.cs. Navigate to the ApplicationUser class.

From there you could add custom properties. Since you are using code-first, Entity Framework will automatically map the property for you when you update-database just be sure to supply the data annotation

ForeignKey("PropertyName")
public class ApplicationUser : IdentityUser
{
        public string GivenName { get; set; }
        public string MiddleName { get; set; }
        public string LastName { get; set; }

        public int? EmployeeId{ get; set; }
        [ForeignKey("EmployeeId")]
        public Employee Employee{ get; set; }
}

Upvotes: 2

Related Questions