Microsoft 开发人员网络 > 论坛主页 > ADO.NET Entity Framework and LINQ to Entities > Error 3034: Two entities with different keys are mapped to the same row
提出问题提出问题
 

已答复Error 3034: Two entities with different keys are mapped to the same row

  • 2008年12月9日 15:24Troels Larsen 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    Can anyone explain what the problem with our model is.. I have narrowed it down as much as possible, but I can't seem to get any further. Due to backwards-compatability reasons, any model change is expensive, time-wise.

    I've posted a simplified 3-table example (complete ssdl,csdl,mdl) at: http://pastebin.com/m1f1e472c

    The problem is that I get the following errors:
    Error 3034: Problem in Mapping Fragments starting at lines 441, 567: Two entities with different keys are mapped to the same row. Ensure these two mapping fragments do not map two groups of entities with overlapping keys to the same group of rows.
    Error 3034: Problem in Mapping Fragments starting at lines 441, 531: Two entities with different keys are mapped to the same row. Ensure these two mapping fragments do not map two groups of entities with overlapping keys to the same group of rows.
    Error 3034: Problem in Mapping Fragments starting at lines 441, 537: Two entities with different keys are mapped to the same row. Ensure these two mapping fragments do not map two groups of entities with overlapping keys to the same group of rows.
    Error 3034: Problem in Mapping Fragments starting at lines 441, 543: Two entities with different keys are mapped to the same row. Ensure these two mapping fragments do not map two groups of entities with overlapping keys to the same group of rows.
    Error 3034: Problem in Mapping Fragments starting at lines 441, 555: Two entities with different keys are mapped to the same row. Ensure these two mapping fragments do not map two groups of entities with overlapping keys to the same group of rows.
    Error 3034: Problem in Mapping Fragments starting at lines 441, 561: Two entities with different keys are mapped to the same row. Ensure these two mapping fragments do not map two groups of entities with overlapping keys to the same group of rows.

    I've tried looking in this forum, but I can't seem to figure out what is causing the problem.

    I have the following entities:

    MAT (Material)
    STD_MAT (Standard Material)
    UNIT (Unit)

    STD_MAT inherits from MAT
    STD_MAT has four UNITS, thourgh foreign keys STD_MAT_UNIT_FK, STD_MAT_UNIT_FK_1,STD_MAT_UNIT_FK_2,STD_MAT_UNIT_FK_3

    This appears to be causing the problem, but why?
    - Have I made an error in having STD_MAT inherit from MAT?
    - Is there a fundamental problem with the four relations? (When I delete three of the four relationships, the model builds)

答案

  • 2008年12月10日 0:27Srikanth Mandadi - MSFT 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复

    Looks like there are a few AssociationSetMappings that are missing conditions. Did you hand edit the xml for edmx? If you did not edit the xml directly this might be a bug in designer. let us know so that we can track down the problem.

    Below is an xml fragment from msl file that I had to change to get this working.

     

    Thanks

    Srikanth.

     

              <AssociationSetMapping Name="DEMO71_STD_MAT_UNIT_FK_4" TypeName="Model.DEMO71_STD_MAT_UNIT_FK_4" StoreEntitySet="STD_MAT">
                <EndProperty Name="STD_MAT">
                  <ScalarProperty Name="MAT_NO" ColumnName="STD_MAT_NO" /></EndProperty>
                <EndProperty Name="UNIT">
                  <ScalarProperty Name="UNIT_ID" ColumnName="UNIT_ID_3" /></EndProperty>
                <Condition IsNull="false" ColumnName="UNIT_ID_3"/>
                </AssociationSetMapping>
              <AssociationSetMapping Name="DEMO71_STD_MAT_UNIT_FK_3" TypeName="Model.DEMO71_STD_MAT_UNIT_FK_3" StoreEntitySet="STD_MAT">
                <EndProperty Name="STD_MAT">
                  <ScalarProperty Name="MAT_NO" ColumnName="STD_MAT_NO" /></EndProperty>
                <EndProperty Name="UNIT">
                  <ScalarProperty Name="UNIT_ID" ColumnName="UNIT_ID_2" /></EndProperty>
                <Condition IsNull="false" ColumnName="UNIT_ID_2"/>
                </AssociationSetMapping>
              <AssociationSetMapping Name="DEMO71_STD_MAT_UNIT_FK_2" TypeName="Model.DEMO71_STD_MAT_UNIT_FK_2" StoreEntitySet="STD_MAT">
                <EndProperty Name="STD_MAT">
                  <ScalarProperty Name="MAT_NO" ColumnName="STD_MAT_NO" /></EndProperty>
                <EndProperty Name="UNIT">
                  <ScalarProperty Name="UNIT_ID" ColumnName="UNIT_ID_1" /></EndProperty>
                <Condition IsNull="false" ColumnName="UNIT_ID_1"/>
                </AssociationSetMapping>
              <AssociationSetMapping Name="DEMO71_STD_MAT_UNIT_FK" TypeName="Model.DEMO71_STD_MAT_UNIT_FK" StoreEntitySet="STD_MAT">
                <EndProperty Name="STD_MAT">
                  <ScalarProperty Name="MAT_NO" ColumnName="STD_MAT_NO" /></EndProperty>
                <EndProperty Name="UNIT">
                  <ScalarProperty Name="UNIT_ID" ColumnName="STOCK_UNIT_ID" /></EndProperty>
                </AssociationSetMapping>
              <AssociationSetMapping Name="DEMO71_STD_MAT_STD_MAT_FK_2" TypeName="Model.DEMO71_STD_MAT_STD_MAT_FK_2" StoreEntitySet="STD_MAT">
                <EndProperty Name="STD_MAT1">
                  <ScalarProperty Name="MAT_NO" ColumnName="STD_MAT_NO" /></EndProperty>
                <EndProperty Name="STD_MAT">
                  <ScalarProperty Name="MAT_NO" ColumnName="REPLACE_BY_STD_MAT_NO" /></EndProperty>
                <Condition IsNull="false" ColumnName="REPLACE_BY_STD_MAT_NO"/>
                </AssociationSetMapping>
              <AssociationSetMapping Name="DEMO71_STD_MAT_STD_MAT_FK_3" TypeName="Model.DEMO71_STD_MAT_STD_MAT_FK_3" StoreEntitySet="STD_MAT">
                <EndProperty Name="STD_MAT1">
                  <ScalarProperty Name="MAT_NO" ColumnName="STD_MAT_NO" /></EndProperty>
                <EndProperty Name="STD_MAT">
                  <ScalarProperty Name="MAT_NO" ColumnName="SUBSTITUTE_STD_MAT_NO" /></EndProperty>
                <Condition IsNull="false" ColumnName="SUBSTITUTE_STD_MAT_NO"/>
                </AssociationSetMapping>
              <AssociationSetMapping Name="DEMO71_STD_MAT_STD_MAT_FK" TypeName="Model.DEMO71_STD_MAT_STD_MAT_FK" StoreEntitySet="STD_MAT">
                <EndProperty Name="STD_MAT1">
                  <ScalarProperty Name="MAT_NO" ColumnName="STD_MAT_NO" /></EndProperty>
                <EndProperty Name="STD_MAT">
                  <ScalarProperty Name="MAT_NO" ColumnName="REPLACEMENT_FOR_STD_MAT_NO" /></EndProperty>
                <Condition IsNull="false" ColumnName="REPLACEMENT_FOR_STD_MAT_NO" />
                </AssociationSetMapping>

全部回复

  • 2008年12月10日 0:27Srikanth Mandadi - MSFT 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复

    Looks like there are a few AssociationSetMappings that are missing conditions. Did you hand edit the xml for edmx? If you did not edit the xml directly this might be a bug in designer. let us know so that we can track down the problem.

    Below is an xml fragment from msl file that I had to change to get this working.

     

    Thanks

    Srikanth.

     

              <AssociationSetMapping Name="DEMO71_STD_MAT_UNIT_FK_4" TypeName="Model.DEMO71_STD_MAT_UNIT_FK_4" StoreEntitySet="STD_MAT">
                <EndProperty Name="STD_MAT">
                  <ScalarProperty Name="MAT_NO" ColumnName="STD_MAT_NO" /></EndProperty>
                <EndProperty Name="UNIT">
                  <ScalarProperty Name="UNIT_ID" ColumnName="UNIT_ID_3" /></EndProperty>
                <Condition IsNull="false" ColumnName="UNIT_ID_3"/>
                </AssociationSetMapping>
              <AssociationSetMapping Name="DEMO71_STD_MAT_UNIT_FK_3" TypeName="Model.DEMO71_STD_MAT_UNIT_FK_3" StoreEntitySet="STD_MAT">
                <EndProperty Name="STD_MAT">
                  <ScalarProperty Name="MAT_NO" ColumnName="STD_MAT_NO" /></EndProperty>
                <EndProperty Name="UNIT">
                  <ScalarProperty Name="UNIT_ID" ColumnName="UNIT_ID_2" /></EndProperty>
                <Condition IsNull="false" ColumnName="UNIT_ID_2"/>
                </AssociationSetMapping>
              <AssociationSetMapping Name="DEMO71_STD_MAT_UNIT_FK_2" TypeName="Model.DEMO71_STD_MAT_UNIT_FK_2" StoreEntitySet="STD_MAT">
                <EndProperty Name="STD_MAT">
                  <ScalarProperty Name="MAT_NO" ColumnName="STD_MAT_NO" /></EndProperty>
                <EndProperty Name="UNIT">
                  <ScalarProperty Name="UNIT_ID" ColumnName="UNIT_ID_1" /></EndProperty>
                <Condition IsNull="false" ColumnName="UNIT_ID_1"/>
                </AssociationSetMapping>
              <AssociationSetMapping Name="DEMO71_STD_MAT_UNIT_FK" TypeName="Model.DEMO71_STD_MAT_UNIT_FK" StoreEntitySet="STD_MAT">
                <EndProperty Name="STD_MAT">
                  <ScalarProperty Name="MAT_NO" ColumnName="STD_MAT_NO" /></EndProperty>
                <EndProperty Name="UNIT">
                  <ScalarProperty Name="UNIT_ID" ColumnName="STOCK_UNIT_ID" /></EndProperty>
                </AssociationSetMapping>
              <AssociationSetMapping Name="DEMO71_STD_MAT_STD_MAT_FK_2" TypeName="Model.DEMO71_STD_MAT_STD_MAT_FK_2" StoreEntitySet="STD_MAT">
                <EndProperty Name="STD_MAT1">
                  <ScalarProperty Name="MAT_NO" ColumnName="STD_MAT_NO" /></EndProperty>
                <EndProperty Name="STD_MAT">
                  <ScalarProperty Name="MAT_NO" ColumnName="REPLACE_BY_STD_MAT_NO" /></EndProperty>
                <Condition IsNull="false" ColumnName="REPLACE_BY_STD_MAT_NO"/>
                </AssociationSetMapping>
              <AssociationSetMapping Name="DEMO71_STD_MAT_STD_MAT_FK_3" TypeName="Model.DEMO71_STD_MAT_STD_MAT_FK_3" StoreEntitySet="STD_MAT">
                <EndProperty Name="STD_MAT1">
                  <ScalarProperty Name="MAT_NO" ColumnName="STD_MAT_NO" /></EndProperty>
                <EndProperty Name="STD_MAT">
                  <ScalarProperty Name="MAT_NO" ColumnName="SUBSTITUTE_STD_MAT_NO" /></EndProperty>
                <Condition IsNull="false" ColumnName="SUBSTITUTE_STD_MAT_NO"/>
                </AssociationSetMapping>
              <AssociationSetMapping Name="DEMO71_STD_MAT_STD_MAT_FK" TypeName="Model.DEMO71_STD_MAT_STD_MAT_FK" StoreEntitySet="STD_MAT">
                <EndProperty Name="STD_MAT1">
                  <ScalarProperty Name="MAT_NO" ColumnName="STD_MAT_NO" /></EndProperty>
                <EndProperty Name="STD_MAT">
                  <ScalarProperty Name="MAT_NO" ColumnName="REPLACEMENT_FOR_STD_MAT_NO" /></EndProperty>
                <Condition IsNull="false" ColumnName="REPLACEMENT_FOR_STD_MAT_NO" />
                </AssociationSetMapping>

  • 2008年12月10日 7:58Troels Larsen 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    Thanks.. I'll try it out right away.. And no - the version I posted here was not edited by hand. I can see that at least one other person had a similar problem:

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3791719&SiteID=1
  • 2008年12月10日 8:01Troels Larsen 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    Thanks again - that fixed it! Thanks for the fast and precise response Smile
  • 2008年12月12日 4:13dj12345 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    It's Dec 11, 2008. Just had the same exact problem. Wasted probably the same amount of time as everyone else. Manually adding the <Condition/> tags fixed it. The posts at http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3791719&SiteID=1 are dated August, etc. Why are programmers having to waste time wondering what they are doing wrong (nothing) and then eventually having to manually work around this Designer bug after all this time? Sure would be nice if a fix for this were released soon.
  • 2009年2月3日 2:16PreMagination 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    I too experienced the same (frustrating) bug described here and in other posts. After adding TPT inheritance to an existing EDM I had to edit the .edmx file by hand in several places. I had previously only used the Designer to modify the file. VS2008 SP1, .NET 3.5 SP1, Vista64, SqlExpress 2008.
  • 2009年11月8日 9:52MickeyVip 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    Hello!

    I would like to quote (with some book's project specifics ommited) from the book "Programming Entity Framework" by Julia Lerman, O'Reilly:

    There is a bug in the Designer that is related to 0..1:* mappings. You should create the mapping first as a 1:* (...), and then define the mappings... Then return to the association's properties and change the ... end to 0..1 ("zero or one"). The Designer must insert a condition element for the mapping but neglects to when mapping a 0..1 end. By performing the steps in this order, the condition element will be inserted properly. Follow the same steps for the other 0..1:* associations. "

    So the alternative to manual updating .edmx file would be altering "0..1" ends to "1", building the project and then reversing those ends to "0..1" again.

    Hope it simplifies fixing the problem.

    Thanks Julia Lerman and O'Reilly.