아래와 같은 관계를 구축 할 수 있습니까?EF - 기본 키가 아닌 Identity를 설정하고 다른 테이블의 외래 키로 사용
또는 이것을 만드는 가장 좋은 방법은 무엇입니까?
외부 키로 구성된 합성 키를 가진 부모 테이블 SnapShotPriceList
이 있으며이 테이블에 고유 한 레코드를 제공합니다.
자식 테이블을 생성 SnapPriceListProcess
만들고이 복잡한 키를 사용하지 않고 고유 한 열을 사용하여 부모 테이블과 관계를 설정하고 싶습니다. 이게 말이 돼? 나는 그런 것을 할 수 있습니까? SnapPricelistId
을 추가 하시겠습니까? 팁을 주셔서 감사합니다.
[Table("SnapShotPriceList")]
public class SnapShotPriceList
{
// auton increment but not primary key
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int SnapPriceListId { get; set; }
[Key, Column("ProjectId", Order = 0)]
public int ProjectId { get; set; }
[Key, Column("PriceListId", Order = 1)]
public int PriceListId { get; set; }
public int CrtUsrnm { get; set; }
public DateTime CrtTmstmp { get; set; }
[ForeignKey("PriceListId")]
public virtual PriceList PriceList { get; set; }
[ForeignKey("PriceListId, ProjectId")]
public virtual ProjectPriceList ProjectPriceList { get; set; }
public ICollection<SnapShotPriceListProcess> SnapShotPriceListProcesses { get; set; }
}
[Table("SnapPriceListProcess")]
public class SnapShotPriceListProcess
{
[Key, Column("SnapProcessId", Order = 0)]
public int SnapProcessId { get; set; }
[ForeignKey("SnapPriceListId")]
public virtual SnapShotPriceList SnapShotPriceList{ get; set; }
// some other fields
}