0
두 모델간에 관계를 만드는 데 문제가 있습니다. 테이블에는 3 개의 복합 키가 있습니다. Category.Code를 Service.CategoryCode에 연결하려고하면이 문제가 발생합니다. 두 테이블 모두에서 동일한 열 이름을 사용하면 EF가 처리 할 수 있습니다. 하지만 Category.CategoryCode를 사용하고 싶지 않습니다. 나는 EF에 처음 온 사람이다. 주석 달기 및/또는 유창한 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; }
}
가능한 중복 http://stackoverflow.com/ 질문/11148662/mapping-a-foreign-key-with-custom-column-name-in-entity-framework-4-3-code-fir) –
정말로'ApplicationCode'와'CompanyCode'를 포함해야합니까? '서비스'PK에? –