アプリを接続する必要がある従来のテーブルがあります。コードファーストの POCO モデルを使用しています。私は次のクラスを持っています:
public class Equipment
{
[Key]
public string EquipmentId { get; set; }
public string OriginatorId { get; set; }
public virtual Employee Employee { get; set; }
}
public class Employee
{
[Key]
[Column("employee_id")]
public string EmployeeId { get; set; }
public string EmployeeName { get; set; }
[ForeignKey("OriginatorEmployeeId")]
public virtual Equipment Equipment { get; set; }
}
Employee クラスの EmployeeId を Equipment クラスの OriginatorEmployeeId にマップする必要があります。
また、従来のテーブルは Employee クラスによって表されます。テーブルの名前は実際には employee (小文字) で、EmployeeId 列の名前は「employee_id」です。クラスとプロパティの名前をアプリの残りの部分と一致させたいので、Employee と EmployeeId.
流暢なAPIを使用して試したことは次のとおりです。
modelBuilder.Entity<Employee>().Map(m =>
{
m.MapInheritedProperties();
m.ToTable("employee");
});
modelBuilder.Entity<Equipment>()
.HasOptional<Employee>(u => u.Employee)
.WithOptionalDependent(c => c.Equipment).Map(p => p.MapKey("OriginatorEmployeeId"));
私はおそらく必要のないものを混ぜています。私が今得ているエラーは次のとおりです。
Multiplicity is not valid in Role 'Equipment_Employee_Source' in relationship 'Equipment_Employee'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be '*'.
どんな助けでも大歓迎です。