September 2017 - Digital Tool Factory blog September 2017 - Digital Tool Factory blog

The Digital Tool Factory Blog

The peculiar problem when your entity framework query returns the same row for every record

This one had me confused for a long time, several hours in fact.  There were over 8,000 rows in the table, and the for some reason the query was returning the same row 8,000 times.  After much rending of garments and gnashing of teeth, I discovered that the table in question (in a sql server 2000 database (not created by me)) had no primary key defined.

So – I copy the data into a new table, create a key with the commands

alter table TableInQuestion
add NewIDColumn int identity(1,1)

Delete the empty key field (that was what threw me, there was a column named “Id”, which was not actually and ID column.) rename “NewIDColumn” to “Id”, then point EF to the new table with the data attribute (on the object)

[Table(“TableInQuestion”)]

and everything works like a charm

 


22
Sep 17


Written By Steve French

 




Copyright 2011 Digital Tool Factory. All Rights Reserved. Powered by raw technical talent. And in this case, WordPress.