I have 2 tables that I import to EF model.
First table has a property [section] that acts as foreign key to the second table.
When I map this property in model to the table and try to compile I get this error:
Problem in Mapping Fragments starting
at lines 158, 174: Non-Primary-Key
column(s) [Section] 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.
If i remove this property from the model it passes, but when I query the data I don’t have the section field.
I know that I can get it by using the navigation field and reading this property from the second table, but to make it work I must include the other table in my query.
var res = from name in Context.Table1.Include("Table2")...
Why do I need to include the association just for one field?
UPDATE
To make it more clear:
Table 1 has fields:
ItemId – key
section – foreign key
title
Table 2 has fields:
SectionId – key
Name
When I set the associations the section property from the first table must be removed.
In EF 4 you can use FK associations for this.
In EF 1 the easiest way to get one field from a related table is to project:
If it’s a key property, you can get the value via the
EntityKey:Generally, I don’t like this last method. It’s too EF-specific, and fails if your query
MergeOptionis set toNoTracking.