4

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'm struggling with entity relationships. I have a database that has two tables that are set up something like this:

Table Keys

I simply want to join them in EF as a One-To-Many relationship joined on PART_SEQ_ID alone so that I can use LINQ to query. When I make the join in the model view EF adds the other key fields to the join and guesses at the related fields. If I don't join the tables, I get an error

Problem in mapping fragments starting at line 294:No mapping specified for properties

and

Problem in mapping fragments starting at line 254:Potential runtime violation of table PARTDETAILS keys

Am I doing something wrong? I found this SO post which indicates this may not be possible. If it's not possible, what is the best way to handle situations like this?

Community
  • 1
  • 1
mack
  • 2,715
  • 8
  • 40
  • 68

1 Answers1

2

I don't think you're going to get navigators to work with your schema as it is. Either you would change your schema so that each table has a unique, immutable, single-column primary key, or you would manage the joins in your query:

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

Pay attention to the generated sql and look at your execution plan to ensure you have the needed indexes to efficiently construct your composition.

Jeff Dunlop
  • 893
  • 1
  • 7
  • 20
  • Thanks @WinstonWolfIT. So I should be able to add the entities to the edmx file without any joins and do the joins in LINQ? – mack Oct 10 '14 at 19:31