0
すでに多くの質問を読んでいますが、私の問題の解決策はまだ見つかりませんでした。私はこのような何かを持ってしようとしていますFKに適切な列を使用しない任意の関係にEFが必要
は、私は非常に迅速に
まず試しdrawed:それは私のエンジンのテーブルに新しい列を作成し、このソリューションを使用して
public class CarMap : EntityTypeConfiguration<Car>
{
public CarMap()
{
ToTable("Cars", Constants.Schema);
Property(t => t.EngineId);
HasRequired(x => x.SPropertyPolicyInsurance).WithMany().HasForeignKey(x => x.SPropertyPolicyInsuranceId);
}
}
public class Car : MyBase
{
public int EngineId { get; set; }
public virtual Engine Engine { get; set; }
}
public class EngineMap : EntityTypeConfiguration<Engine>
{
public EngineMap()
{
ToTable("Engines", Constants.Schema);
Property(t => t.MyField1).HasColumnType("nvarchar").HasMaxLength(128).IsRequired();
Property(t => t.MyField2).HasColumnType("nvarchar").HasMaxLength(128).IsRequired();
Property(t => t.MyField3).HasColumnType("bit").IsRequired();
}
}
public class Engine : MyBase
{
public string MyField1 { get; set; }
public string MyField2 { get; set; }
public bool MyField3 { get; set; }
public virtual Car Car { get; set; }
}
こと私はしたくない...
2回目:
次のコードにCarMapを変更する:問題は、それが私のFKキーの値を格納する列ENGINEIDを使用していないということです
public class CarMap : EntityTypeConfiguration<Car>
{
public CarMap()
{
ToTable("Cars", Constants.Schema);
Property(t => t.EngineId);
HasRequired(x => x.Engine).WithOptional(p => p.Car);
}
}
...
はのためのありがとうございましたとにかく助けてください...