Structural relationships of entities by non-primary keys

I am using VS 2010 with .Net version 4.0 and EF version 5 with an existing database. This is my first project using EF and I am struggling with entity relationships. I have a database that has two tables set up something like this:

Table Keys

I just want to join them in EF as a one-to-many relationship related only to PART_SEQ_ID so that I can use LINQ to query. When I make a join to the model view, EF adds other key fields to the join and guesses in the related fields. If I don't join tables I get the error

Issue displaying snippets starting at line 294: no mapping specified for properties


Fragment rendering issue starting at line 254: Potential table runtime violation. PARTDETAILS Keys

Am I doing something wrong? I found this SO post stating that this might not be possible. If this is not possible, what is the best way to handle such situations?


source to share

1 answer

I don't think you are going to make the navigators work with your schematic the way they are. Either you change the schema so that each table has a unique, immutable primary key with one column, or you could manipulate the joins in your query:

from detail in partdetails
join part in parts on detail.part_seq_id equals part.part_seq_id...


Take a look at the generated sql and look at your execution plan to make sure you have the necessary indexes to build your composition efficiently.



All Articles