Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity framework query returns the same row multiple times

This is my first time using the Entity Framework and I'm getting some confusing results. I know a particular table contains 3 distinct rows when I run this SQL query:

SELECT * FROM mytable WHERE service_month = 201012

When I run this query against the framework however, I get 3 rows, but they are all copies of the first row (VB syntax).

Dim temp = _context.mytable.Where(Function(x) x.service_month = 201012)

Did I set up something incorrectly? This is how I'd do it with LINQ to SQL so I feel like I'm missing something.

like image 620
gfrizzle Avatar asked Aug 31 '11 12:08

gfrizzle


1 Answers

Fix your primary key definition in your EDMX. (If your table has no PK, add one.) When all rows return the same "key", the EF returns the same object instance.

like image 75
Craig Stuntz Avatar answered Oct 14 '22 21:10

Craig Stuntz