EF Core 2.0.0一对一或零,流畅的Api

问题描述 投票:4回答:1

在EF Core 2.0.0的Fluent Api中,没有任何方法HasRequiredHasOptional,我有两个模型,人员和员工:

    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可能有雇员:Optional
  • Employee应该有人:Required

如何在数据库中应用这些约定。

entity-framework entity-framework-core
1个回答
1
投票

你可以指定int吗?作为EmployeeId属性类型。

顺便说一句,不需要虚拟导航属性。

© www.soinside.com 2019 - 2024. All rights reserved.