Entity framework - “Problem in mapping fragments”-error. Help me understand the explanations of this error

后端 未结 12 1775
不知归路
不知归路 2020-12-15 02:49

Error 3007: Problem in Mapping Fragments starting at lines 186, 205: Non-Primary-Key column(s) [WheelID] are being mapped

相关标签:
12条回答
  • 2020-12-15 03:22

    I've had this happen because Entity Framework Update wizard mismapped some keys (or did not update?). As a result, some columns were mistakenly labeled as keys, while actual key columns were treated as plain columns.

    The solution was to manually open EDMX file, find the entities, and update the keys.

    0 讨论(0)
  • 2020-12-15 03:22

    in my case I solved this error by tick (include foreign key columns in the model)

    - update Model from database
    - tick (include foreign key columns in the model)
    - finish 
    

    0 讨论(0)
  • 2020-12-15 03:23

    Solution is to allow deleting Rule = Cascade on Sql association.

    Same thing as to be done on .edmx model, adding element to association:

    <Association Name="FK_Wheels_Slices">
              <End Role="Wheels" Type= "your tipe here" Multiplicity="1">
              <OnDelete Action="Cascade" />
              </End>
     </Association>
    
    0 讨论(0)
  • 2020-12-15 03:23

    Couldn't get any of the answer to work with EF6. The problem seems to be the framework doesn't import the foreign keys correctly as Associations. My solution was removing foreign keys from the tables, and then manually adding the associations using Entity Framework model, using the following steps: Entity Framework - Add Navigation Property Manually

    0 讨论(0)
  • 2020-12-15 03:24

    Since Slices.WheelId is an FK, you cannot expose it in your client model, period. There are ways to get the value, though.

    var wheelId = someSlice.Wheels.ID;
    

    Update In EF 4 you can do this by using FK Associations instead of independent associations.

    0 讨论(0)
  • 2020-12-15 03:29

    For LinQ to Entities queries in EF1, my workaround for not having access to the foreign key as a property is with the following code, which does not produce a join query to the associated table:

    dbContext.Table1s.FirstOrDefault(c => (int?)c.Table2.Id == null)
    

    i.e, the generated SQL is:

    ...WHERE ([Extent1].[Table2Id] IS NULL)...
    
    0 讨论(0)
提交回复
热议问题