I'm getting the following error on my database first model in Entity Framework:
Error 3032: Problem in mapping fragments starting at lines 3434, 4312:EntityTypes Model.Docent, Model.Student are being mapped to the same rows in table Attendee. Mapping conditions can be used to distinguish the rows that these types are mapped to.
While I already added conditions to these models:
<EntityTypeMapping TypeName="IsTypeOf(Model.Student)"> <MappingFragment StoreEntitySet="Attendee"> <ScalarProperty Name="Id" ColumnName="atnId" /> <Condition ColumnName="atnTypeId" Value="1" /> </MappingFragment> </EntityTypeMapping>
<EntityTypeMapping TypeName="IsTypeOf(Model.Docent)"> <MappingFragment StoreEntitySet="Attendee"> <ScalarProperty Name="AvailabilityApprovedByType" ColumnName="atnAvailabilityApprovedByAttId" /> <ScalarProperty Name="Id" ColumnName="atnId" /> <Condition ColumnName="atnTypeId" Value="2" /> </MappingFragment> </EntityTypeMapping>
Their is a more complex hierarchy, possibly that's the problem. But I'm unsure how to proceed. This a the hierarchy:
Attendee (Abstract) -> Facility (Type = 3) -> AttendeeCollection (Abstract) -> Team (Type = 4) -> Group (Type = 5) -> Person (Abstract) -> Student (Type = 1) -> Docent (Type = 2)
Well I figured out the problem. The Person entity had mapped scalar properties and associations. The associations where the problem. Because they could be of two types. I could not write in a condition for them because they could map to two properties. So I removed the scalar properties and the table mapping for the Person class altogether.
After that I implemented private versions of these scalar properties on the Docent en Student class. And exposed them via a partial implementation. Where I added them as abstract to the Person class.
I hope this is clear and helps somebody else. Possibly somebody else can write it down more legible.