During developing an application with LINQ to SQL, I found that when a stored procedure returns multiple distinct rows with same primary key then LINQ will make the complete list object same. For example, If I have the following table,
ID Name Salary
-- ---- -----
1 A 20
2 B 200
3 C 30
4 D 520
and my stored procedure returns all rows except with same primary key,
ID Name Salary
-- ---- -----
1 A 20
1 B 200
1 C 30
1 D 520
then linq will bind these rows as,
ID Name Salary
-- ---- -----
1 A 20
1 A 20
1 A 20
1 A 20
It is not a bug it is a feature. Both entity framework and Linq-to-Sql demands uniquely identified entity and entity with each unique key can be loaded only once so when you return multiple records representing same entity type with same key only first record is materialized into entity and this entity is used for representation of all other records with the same key (so it will not only return the same data but the same reference to the entity). It is called identity map and it is key feature of ORM tools.