Frage

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!

War es hilfreich?

Lösung

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.

Andere Tipps

First of all, I am not sure if what you want is possible, EF wants to take care of the discriminator column, and based on the class type, it would like to set the discriminator value, in this case, how is it going to set the value, to which possible one. It makes no difference when loading it from the DB, but a little problematic when trying to serialize it to the DB.

1- have you tried doing multiple maps for each possible value:) You might have an error saying DarkColor has already been mapped.

2- 2nd suggestion is adding a [NotMapped] ColorWeight attribute, and returning dark or white based on theColor, and using this property as the discriminator field, but I guess Discriminator field should exist in the Table.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top