Two entities mapped to the same rows

ef-database-first entity-framework entity-framework-6

Question

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>

And

<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)
1
0
12/9/2016 7:48:02 AM

Popular Answer

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.

0
12/9/2016 8:29:11 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow