0
以下のような関係を構築できますか?EF-set主キーではなく、別のテーブルで外部キーとして使用するIDを設定します。
これを行うにはどうすればよいですか?
私は親テーブル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
}