简体   繁体   中英

Condition one of two properties to be different of null Entity Framework Code First

I am using 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?

It is something like what is answered in this question but with EF.

我认为您必须在其他层(例如您的业务层)中进行此验证,而不是将此职责委托给ef

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM