Entity Framework Query Results Duplicate

1.4k views Asked by At
  • I created a SQL View that joins a few tables and when tested in SQL Manager it provides the correct data (If a makes a difference these are complex joins).
  • In MVC I created a (data first) Entity Data Model and then added code generation.
  • I have a LINQ query in a controller that generates an idex page.

All basic MVC stuff.

When I run the application I receive duplicate records. To further qualify, if an order has more than one line it returns the first record for each line in the "order".

SQL Results
Order, Line, Part
12345, 1, 3829138120
12345, 2, 1238401890

MVC/EF Results
Order, Line
12345, 1, 3829138120
12345, 1, 3829138120

Any thoughts as to the cause of this problem?

1

There are 1 answers

2
dani herrera On BEST ANSWER

You should double check the entity key attributes. I see your query result and you should mark as primary key Order and Line and I think that you have forget mark order as key.