【发布时间】:2021-06-21 05:44:30
【问题描述】:
我想使用 EF 6、代码优先和流畅的配置创建一对一的关系。我只想要根目录中的导航属性。这可能吗?如果是这样,我该如何配置我的EntityTypeConfigurations?我需要将SalarayId 更改为EmployeeId 吗?
public class Employee
{
public int EmployeeId { get; set; }
public string Name { get; set; }
public virtual Salary Salary {get; set; }
}
public class Salary
{
public int SalaryId { get; set; }
public double Amount { get; set; }
}
public class EmployeeConfiguration : EntityTypeConfiguration<Employee>
{
public EmployeeConfiguration()
{
HasKey(e => e.EmployeeId);
}
}
public class SalaryConfiguration : EntityTypeConfiguration<Salary>
{
public SalaryConfiguration()
{
HasKey(s => s.SalaryId);
}
}
【问题讨论】:
标签: c# entity-framework entity-framework-6 ef-code-first