I want a list of contact with a company. But Company is referenced by ContactExtension and ContactExtension is referenced by Contact. I'm not sure it's possible but I try this:
[Table("Company", Schema = "dbo")]
public class Company
{
[Column("ID")]
[Key]
public int ID { get; set; }
[Column("Name")]
public String Name { get; set; }
[ForeignKey(?)]
public virtual ICollection<Contact> MyContacts { get; set; }
}
[Table("Contact", Schema = "dbo")]
public class Contact
{
[Column("ID")]
[Key]
public int ID { get; set; }
[Column("Name")]
public String Name { get; set; }
[Column("ContactExtensionID")]
public int ContactExtensionID { get; set; }
[ForeignKey("ContactExtensionID")]
public virtual ContactExtension ContactExtension { get; set; }
}
[Table("ContactExtension", Schema = "dbo")]
public class ContactExtension
{
[Column("ID")]
[Key]
public int ID { get; set; }
[Column("Name")]
public String Name { get; set; }
[Column("CompanyID")]
public int CompanyID { get; set; }
}
If I write ForeignKey["CompanyID"]
, there is a problem because there is no CompanyID column in Contact.
How can I specify the foreignKey CompanyID is in ContactExtension?
I want to find a solution without Fluent Api
.