I have two entity classes, Contact and User.
The User has ContactID as foreign key to Contact. I can show relation of the User to Contact.
Now i also need Contact to User relation with the same foreign key in User table (not in Contact)
public class Contact{
public int ContactID {get;set;}
// This relation doesn't work
// Need to Make this Work
public User ContactUser {get;set;}
}
public class User {
public string Id {get;set;}
public int? ContactID {get;set;}
// This Relation works
[ForeignKey("ContactID")]
public Contact Contact {get;set;}
}
So i need to make the ContactUser relation work on Contact. What kind of mapping should i use?
Edit
As suggested I used :
modelBuilder.Entity<Contact>().HasRequired(c => c.ContactUser).WithOptional(pi => pi.Contact);
I removed ForeignKey attribute from User, it as causing Multiplicity...error
But i get error Like: Invalid column name 'User_Id'.