[英]Condition one of two properties to be different of null Entity Framework Code First
I am using EF6 Code First. 我正在使用EF6 Code First。 Suppose the following scenario. 假设以下情况。 We have this class: 我们有这个课:
class Foo
{
public int Id { get; set; }
public A AProperty { get; set; }
public B BProperty { get; set; }
}
Is there a way, by using either Data Annotations or Entity Framework Fluent Api and without redesigning the whole model, to ensure that any Foo entity must have either at least one property different of null but not both? 是否有办法通过使用数据注释或实体框架Fluent Api而无需重新设计整个模型来确保任何Foo实体必须至少具有一个不同于null的属性,而不能同时具有两者?
It is something like what is answered in this question but with EF. 这个问题的答案与EF类似。
我认为您必须在其他层(例如您的业务层)中进行此验证,而不是将此职责委托给ef
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.