I am having problem making a relationship between the two models. There are 3 composite keys in the tables. The problem occurs when I try to link the Category.Code to Service.CategoryCode. If I use the same column names in both tables, EF is able to handle. But I don't want to use Category.CategoryCode. I am new to EF. Please help me on how to achieve this by annotating and/or fluent api.
public class Category
{
public Category()
{
this.Services= new HashSet<Service>();
}
[Key, Column(Order = 0)]
public string ApplicationCode { get; set; }
[Key, Column(Order = 1)]
public string CompanyCode { get; set; }
[Key, Column(Order = 2)]
public string Code { get; set; }
public string Description { get; set; }
public virtual ICollection<Service> Services { get; set; }
}
public class Service
{
[Key, Column(Order = 0)]
[ForeignKey("Category")]
public string ApplicationCode { get; set; }
[Key, Column(Order = 1)]
[ForeignKey("Category")]
public string CompanyCode { get; set; }
[Key, Column(Order = 2)]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Id { get; set; }
[ForeignKey("Category")]
public string CategoryCode { get; set; }
public string Description { get; set; }
public string Remarks { get; set; }
public virtual Category Category { get; set; }
}