Error 3032: Problem in mapping fragments : mapped to the same rows in table
Today I tried creating a two-level hierarchy using Entity Framework 4 but using the same discriminator column for both layers of the hierarchy. It seems you cannot do this but instead must have a separate column for each layer of the hierarchy. Makes some sense but the error message wasn't very helpful.
I have a table-per-hierarchy model, one abstract class (Node), a column that differentiates the sub-classes (NodeType), and three sub-classes (NodeClass, NodeProperty, NodeIndividual) with conditions (NodeType=1, 2, 3), it's working just fine.
I now want to add another sub-class which itself has three sub-classes. So I create the new sub-class marking it abstract (NodeLiteral), I create the three derived types inheriting from it (NodeiteralInt, NodeLiteralDouble, NodeLiteralDateTime) and add conditions on them based on the same discriminator column used in the first level of inherited classes (NodeType=101,102,103).
When I compile I get:-
Error 3032: Problem in mapping fragments starting at lines ... (classes) ... are being mapped to the same rows in table Node. Mapping conditions can be used to distinguish the rows that these types are mapped to.
Since I DO have mapping conditions that are distinct for each of these classes the error message is somewhat confusing.
If I add another column and use that as the discriminator for the second level of inheritance it works.
So if you are trying to model a two or more layer hierarchy in EF don't try to use a single column for all your conditions, create a column for each layer of the hierarchy instead.