if I have the following models, am I using the InverseProperty correctly?
class Person {
public int PersonID {get;set;}
[InverseProperty(\"Person\")]
public
First, This looks strange : you are creating multiple mapping to the same object qwith different names ?
[InverseProperty("Person")]
public List Sports {get;set;}
[InverseProperty("Person")]
public List Art {get;set;}
[InverseProperty("Person")]
public List Reading {get;set;}
It should be something like :
[InverseProperty("Person")]
public virtual List Hobbies {get;set;}
[NotMapped]
public List Sports
{
get
{
return this.Hobbies.OfType().ToList();
}
}
[NotMapped]
public List Art
{
get
{
return this.Hobbies.OfType().ToList();
}
}
[NotMapped]
public List Readings
{
get
{
return this.Hobbies.OfType().ToList();
}
}
If you set the property Person in the abstract class, then the mapping must be to the abstract class.
Otherwise, you have to declare the PersonId in the abstract class and then set the Person property in every concrete class using the attribute [ForeignKey("PersonId")]. But this solution is pretty strange.
Secondly, if you want to specify the ForeignKey for the Person, you should use :
[ForeignKey("PersonID")]
public virtual Person Person {get;set;}
Third : Are you sure you don't need M-N relation? Do you really want every people to create new Hobbies (you would finally have multiple times "Driving" (or whatever) as a hobby).