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

entity-framework

Question

Error 3007: Problem in Mapping Fragments starting at lines 186, 205: Non-Primary-Key column(s) [WheelID] are being mapped in both fragments to different conceptual side properties - data inconsistency is possible because the corresponding conceptual side properties can be independently modified.

I found several places on the web describing this error, but I simply don't understand them. (confused smiley goes here)

One
Two
Three
Four

There is something pretty fundamental here, I must be missing. Can you explain it, so that I understand it? Maybe using my real life example below?

alt text http://i39.tinypic.com/2hppnoo.jpg

Foreign key 1:N Wheels.Id -> Slices.WheelId

I add them to entity framework, and WheelId is not visible in the Slices-entity.

alt text http://i43.tinypic.com/287hq87.jpg

Doing some workaround (deleting the relationship from the db before adding tables to EF - then re-creating it and updating EF) I managed to get the WheelId to stay in Slices, but then I get the error mentioned at the top.

Accepted Answer

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.


Popular Answer

Try to remove foreign property column from Entity set using entity model design it will solve your problem

For example

We have two tables one is customer and other one is order, using entity model design we added association between customers and orders when we do this Ado.net entity framework i will add navigation properties to both below tables.

Like Customer.Orders - Here order is list Order.Customer

One - Many relation.

So we need to remove property from with name CustomerId[Foreign key column] from Order entity set.

For reference:

http://social.msdn.microsoft.com/forums/en-US/adodotnetentityframework/thread/2823634f-9dd1-4547-93b5-17bb8a882ac2/



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why