gpt4 book ai didi

c# - EF 核心的 hasRequired 的替代品是什么?

转载 作者:太空宇宙 更新时间:2023-11-03 18:02:26 25 4
gpt4 key购买 nike

使用 Entity Framework,我们在字段上设置了 HasRequired。 EF 核心的替代品是什么?

https://msdn.microsoft.com/en-us/library/jj591620(v=vs.113).aspx

我尝试使用 HasRequired 但它会抛出错误。

最佳答案

查看 Required and Optional Relationships在 EF 核心文档中。

具体来说,我想你会想要这样的东西:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<MyEntity>()
.HasOne(p => p.Relationship)
.IsRequired();
}

或者类似的东西 - 你没有提供太多信息继续进行

关于c# - EF 核心的 hasRequired 的替代品是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50577357/

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