Search code examples
entity-frameworktable-per-hierarchy

Entity Framework - Discriminate on multiple values


In a Table-Per-Hierachy scenario is it possible to discriminate on a list of possible values?

e.g. for the types Color, DarkColor, LightColor

something like

 Map<DarkColor>(m => m.Requires("TheColor").HasValue(Red || Blue)
 Map<LightColor>(m => m.Requires("TheColor").HasValue(Yellow || White)

poor example but hopefully you get the picture!


Solution

  • No, it is not possible.

    Entity framework only enables mapping using a intersection of conditions, not a union of conditions.
    You can see this both in the designer[1] and in the EDMX syntax[2].
    * Code first should have the same mapping capabilities.

    [2] If you right click the edmx file and choose "Open With..." --> "Automatic Editor Selector (XML)" and try to manually edit the mapping conditions you will see (from the intellisense) that the is no option to enter "OR" between conditions.