Two entities mapped to the same rows

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

Question

On my Entity Framework database first model, I'm getting the following error:

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.

Even though I've previously given these models conditions:

<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>

There is a more intricate hierarchy, which may be the issue. But I'm not sure what to do next. The hierarchy is as follows:

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

I did, however, identify the issue. Scalar attributes and relationships had been mapped into the Person object. The issue was with the associations. mainly because there are two kinds of them. They may map to two attributes, thus I was unable to fill in a condition for them. So I completely got rid of the Person class's scalar attributes and table mapping.

Following that, I added private iterations of these scalar attributes to the Student and Docent classes. and revealed them via a shoddy execution. Where I added them to the Person class as abstract.

I really hope this makes sense and helps someone else. Maybe someone else can type it out more clearly.

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