私は次のモデルを持っています:
public class SomeForm
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public IList<FacilityContactInformation> OriginatingFacilities { get; set; }
public IList<FacilityContactInformation> DestinationFacilities { get; set; }
}
public class FacilityContactInformation
{
public FacilityContactInformation()
{
Id = -1;
}
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[MaxLength(50)]
public string Owner { get; set; }
}
自動移行を使用して、データベース スキーマを生成および再生成しています。
これにより、「外部キー 'FK_dbo.FacilityContactInformations_dbo.SomeForm_SomeForm_Id' は、参照テーブル 'FacilityContactInformations' で無効な列 'SomeForm_Id' を参照しています。制約を作成できませんでした。前のエラーを参照してください。
根本的な原因は、EF が両方のリストに対して FK FK_dbo.FacilityContactInformations_dbo.SomeForm_SomeForm_Id を生成しようとすることだと思われます
自動移行を使用し続ける方法はありますが、これを取得して機能する FK を生成しますか? FK にリスト名を含め、FacilityContactInformations で 2 つのプロパティを生成するか、結合する中間テーブルを生成する必要があるようです。