views:

47

answers:

2

Hi,

I'm trying to create a 1:m relationship using Entity Framework (.net 4.0) and am getting the following error:

App_Code.Model.msl(36,6) : error 3007: Problem in mapping fragments
starting at lines 6, 36:Column(s) [ProductId] are being mapped in
both fragments to different conceptual side properties.

What i have is a Products table, and a Features table. The idea is that Products have many Features. Products each have a ProductId, and the Features have a ProductId foreign key.

Now the catch is that the foreign key doesn't exist in sql server, and i don't want it to. If it did, then it all automagically works nicely.

In the EDMX designer, i created an association from the product to the feature entity, then edited the mapping details of the ProductFeature association to be based on the Features table, which i think would make it work.

Any ideas? Thanks very much.

A: 

This is a M x N relationship. Why? Because a feature can be assigned to more than one type of product.

You should have a table ProductFeatures like so:

ProductId  FeatureId
1          1
1          2
2          1
2          2
Leniel Macaferi
Hi, this is just a simple example for learning purposes, in a real app you're right it'd be like you describe, however in this case i'm trying to get a handle on 1:m relationships.
Chris
A: 

Found one solution: delete the scalar property 'ProductId' from the feature entity:

http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/a71901fb-97ec-4072-949a-c0c66a9775b1

However, in the auto-generated relationships that EF gives you if you set up the foreign key in the database, the eg 'ParentId' fields are present in the child as a scalar field.

So i'm a little confused still.

-edit- Further help:

http://www.hanselman.com/blog/CreatingAnODataAPIForStackOverflowIncludingXMLAndJSONIn30Minutes.aspx

Chris
Probably has to do with the code/xml generated by the designer. I haven't used EF since version 1.0 but I remember there were many things you could do by editing the xml directly that the UI/Designer didn't support.
confusedGeek
Thanks confusedgeek, maybe i'll just chalk this one up to the limitations in VS.
Chris