gpt4 book ai didi

entity-framework - EF Core 2.0.0 一对一或零与 Fluent Api

转载 作者:行者123 更新时间:2023-12-03 07:19:11 24 4
gpt4 key购买 nike

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 May to have Employee: Optional
  • Employee Should have Person: Required

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

最佳答案

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

顺便说一句,无需将导航属性设为虚拟。

关于entity-framework - EF Core 2.0.0 一对一或零与 Fluent Api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48394969/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com