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

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

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

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.


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.


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/


I was able to overcome this problem by the following steps: right click the designer window Select 'update model from database' Select Add AND make sure that the 'Include foreign key columns in the model' checkbox is selected. click on Finish...


I had set foreign keys up in the database but framework still wasn't pulling them in correctly. So I tried to add the association myself. 

However, when I did this I would get a mapping error. It took me A WHILE but I figured out. What I did was set up the association using the entity toolbox association tool and then you have to double click on the association (1 to many) line and set the primary and foreign key there. Hopefully, this to help others who might have the same problem. I couldn't find the answer anywhere.