Click here to Skip to main content
15,878,970 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi programmers,

I have a question that I can't be able to find an answer to. I have a class(job) and i want to set a foreign key to that class and also want each user to have a job and not many job.

This is what I have done but i don't know if it is right. I need a good programmer to please look at my code and correct me on it

C#
public class Job
{
    public int id {get; set;}
    public string Name {get; set;}
    //set user foreign key
    public int UserId {get; set;}
    public virtual ApplicationUser User {get; set;}
}

public class ApplicationUser : IdentityUser
{
    public virtual job Jobs {get; set;}
}

protected override void onModelCreating(DbModelBuiler modelBuilder)
{
    modelBuilder.Entity<job> ().HasRequired(r => r.User);
Posted
Updated 12-May-15 20:25pm
v4
Comments
StM0n 13-May-15 1:56am    
You have some inconsistencies...

* your class is called Job (with a capital J) and the reference in <<ApplicationUser>> is job (with lowercase); same applies to <<onModelCreating>>
* you're using Jobs on <<ApplicationUser>> (plural)... shouldn't this be <<Job>>?
* you bind a job to a user and vice versa. Is this correct?
[no name] 21-May-15 18:08pm    
Thats exactly what i want to do. Binding a job to a user.
So that if a user is signed in, he or she can retrieve his own job details. But i dnt knw if my code is correct

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900