在EF Core 2.0.0的Fluent Api中,没有任何方法HasRequired和HasOptional,我有两个模型,人员和员工:
public class Person
{
public int Id { get; set; }
public int EmployeeId { get; set; }
public virtual Employee Employee { get; set; } // Optional
}
public class Employee
{
public int Id { get; set; }
public int PersonId { get; set; }
public virtual Person Person {get; set; } // Required
}
Person
May to have Employee:Optional
Employee
Should have Person:Required
如何在数据库中应用这些对话.
最佳答案 你可以指定int吗?作为EmployeeId属性类型.
顺便说一句,不需要虚拟导航属性.