I've a problem that's pertinent to TPH, I believe. This is the scenario: We have one table called Artists, that have some properties about artists (like name, minibio, etc) and a byte field that bits are used to determine the kind of artist is it, with values like:
1 - Singer
2 - Actor
4 - Composer
8 - Musician
16 - Director
Note that the same artist can be just of one kind or pertain to more than one. Let's see an example:
+-------------------------------------------------+
| Table: Artist |
+---------------------------------------+---------+
| Name | Kind |
+---------------------------------------+---------+
| Al Pacino | 2 | (Actor)
+---------------------------------------+---------+
| Mel Gibson | 18 | (Actor and Director)
+---------------------------------------+---------+
| Dave Matthews | 15 | (Actor, Singer, Composer and Musician)
+---------------------------------------+---------+
Now, I'm able to do TPH using updatable views with stored procedures (for CRUD).
I also know that it's not possible (for me at least!) do this using conditional mapping since I can't use an expression with bitwise OR, like "(Kind | 2) = 2" in the condition.
I've thought, altenativelly, that change the table structure by splitting de field Kind, into something like:
+-----------------------------------------------------------------------------------------+
| Table: Artist |
+---------------------------------------+-------+--------+----------+----------+----------+
| Name | Actor | Singer | Composer | Musician | Director |
+---------------------------------------+-------+--------+----------+----------+----------+
| Al Pacino | 1 | 0 | 0 | 0 | 0 |
+---------------------------------------+-------+--------+----------+----------+----------+
| Mel Gibson | 1 | 0 | 0 | 0 | 1 |
+---------------------------------------+-------+--------+----------+----------+----------+
| Dave Matthews | 1 | 1 | 1 | 1 | 0 |
+---------------------------------------+-------+--------+----------+----------+----------+
Could work, but doing this, although I can create TPH using the fields in the conditional mapping, the EF (obviously) gives me an error stating that the derived entities (Actor, Singer, etc) are
being mapped to the same rows in the table Artist.
My question is, are there other ways to do that ?
Thanks in advance.