코드를 먼저 사용하여 데이터 프로젝트를 만들고 데이터 주석을 작성하려고하지만 아키텍처에 대한 의문점이 있습니다. 내 관계 스키마가 합리적인지, SQL에서 올바른지, EF에서 구현 가능한지 확실하지 않습니다. 하나의 자식 테이블에서 두 개의 상상력 테이블 중 하나로 조건부 관계를 만드는 방법. 내 ProcessRelation 테이블에서 두 관계를 저장합니다. JobBusinessArea - 견적 및 jobBussinesArea - PriceList. 나는 그 말을하기를 바란다. 도움과 제안을 주셔서 감사합니다.Entity Framework - 조건부 관계 - 하위 테이블 하나 또는 다른 상상력 표
[Table("ProcessRelation")]
public class ProcessRelation
{
[Key, Column("AreaId", Order = 0)]
public int AreaId { get; set; }
[Key, Column("ModId", Order = 1)]
public int ModId { get; set; }
[Key, Column("PriceSourceTypeId", Order = 2)]
public int PriceSourceTypeId { get; set; }
public int CrtUsrnm { get; set; }
public DateTime CrtTmstmp { get; set; }
public int LcUsrnm { get; set; }
public DateTime LcTmstmp { get; set; }
[ForeignKey("PriceSourceTypeId")]
public virtual BillingProjectCode PriceSourceTypeCode { get; set; }
[ForeignKey("AreaId")]
public virtual JobBusinessArea JobBusinessArea { get; set; }
//TODO:
//Depending on the PriceSourceTypeId i would like create reference to PriceListProcessMod Table
//or EstimateProcessMod Table
//[ForeignKey("ModId")]
//public virtual PriceListProcessMod PriceListProcessMod { get; set; }
// or
//public virtual EstimateProcessMod EstimateProcessMod { get; set; }
}
[Table("PriceListProcessMod")]
public class PriceListProcessMod
{
[Key, Column("ModId", Order = 0)]
public int ModId { get; set; }
public int ProcessId { get; set; }
public int Quantity { get; set; }
public bool IsIncluded { get; set; }
public int CrtUsrnm { get; set; }
public DateTime CrtTmstmp { get; set; }
public int LcUsrnm { get; set; }
public DateTime LcTmstmp { get; set; }
public decimal? CommisionPercentage { get; set; }
public bool? IsProportionalyFixed { get; set; }
[ForeignKey("ProcessId")]
public virtual PriceListProcess PriceListProcess { get; set; }
}
[Table("EstimateProcessMod")]
public class EstimateProcessMod
{
[Key, Column("ModId", Order = 0)]
public int ModId { get; set; }
public int? SplitId { get; set; }
public int ProcessId { get; set; }
public int Quantity { get; set; }
public bool IsIncluded { get; set; }
public int CrtUsrnm { get; set; }
public DateTime CrtTmstmp { get; set; }
public int LcUsrnm { get; set; }
public DateTime LcTmstmp { get; set; }
public decimal? CommisionPercentage { get; set; }
public bool? IsProportionalyFixed { get; set; }
[ForeignKey("ProcessId")]
public virtual EstimateProcess EstimateProcess{ get; set; }
}
[Table("JobBusinessArea")]
public class JobBusinessArea
{
[Key, Column("JobBusinessAreaId", Order = 0)]
public int JobBusinessAreaId { get; set; }
public int CrtUsrnm { get; set; }
public DateTime CrtTmstmp { get; set; }
public int LcUsrnm { get; set; }
public DateTime LcTmstmp { get; set; }
public int ProjectId { get; set; }
public int AreaTypeId { get; set; }
public int SourceId { get; set; }
}
SQL 또는 EF에는 조건부 관계가 없습니다. FK 열은 정확히 하나의 대상 PK 열을 대상으로합니다. 귀하의 경우, null 가능 탐색 속성/FK를 사용해야하며 TPH 상속과 쌍을 이룰 수도 있습니다. – DevilSuichiro