EF Core 2.0.0与Fluent Api一对一或零 [英] EF Core 2.0.0 One to One-or-Zero with Fluent Api

查看:116
本文介绍了EF Core 2.0.0与Fluent Api一对一或零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

EF Core 2.0.0 的Fluent Api中,没有任何方法需要 具有可选,我有两个模型,人员和员工:

In Fluent Api at EF Core 2.0.0, there aren't any methods HasRequired and HasOptional, and i have tow Models, Person and Employee:

    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
    }





  • 人员可能有员工:可选

  • Employee 应该有个人: Required

  • Person May to have Employee: Optional
  • Employee Should have Person: Required

如何在数据库中应用这些服务。

How to apply these convetions in database.

推荐答案

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

You could just specify int? as EmployeeId property type.

BTW,无需将导航属性虚拟化。

BTW, no need to make navigation properties virtual.

这篇关于EF Core 2.0.0与Fluent Api一对一或零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆