6
  • 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
  • Perhaps post some scaled down code segments? In particular the LINQ query. Commented Oct 31, 2011 at 15:29

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the insight, danihp. Resolution: To fix the problem I opened the Entity Data Model (edmx file) and select the Field (OrderLine) property in the Entity Set (SalesOrders). Opened the Properties for the field and set the Entity Key value to true. (I also found many fields that were set as Entity Keys that probably shouldn't be.)
Hi Pete, a happy end ... or begin. Good luck with your project and thanks about explaning detailed resolution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.