本文介绍了用EF核心替代hasRequired是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Entity Framework,我们在字段上具有 HasRequired
.用EF核心替代替代品是什么?
With Entity Framework we had HasRequired
on a field. What is the alternative replacement for that with EF core?
https://msdn.microsoft.com/en-us/library/jj591620(v = vs.113).aspx
我尝试了 HasRequired
,但是会引发错误.
I tried with HasRequired
but it throws error.
推荐答案
具体来说,我认为您会想要这样的东西:
Specifically I think you'll want something like:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<MyEntity>()
.HasOne(p => p.Relationship)
.IsRequired();
}
或者类似的东西-您没有提供太多信息来继续
Or something like that - you haven't given much information to go on
这篇关于用EF核心替代hasRequired是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!