LINQ to Entities not returning expected result

前端 未结 1 1647
长情又很酷
长情又很酷 2020-12-21 09:58

I am using a view to return a complex search query. When I usin linq to query against EF it is returning the same row 3 times(the actual rowcount is correct).

using

相关标签:
1条回答
  • 2020-12-21 10:09

    This happens if Patient entity doesn't have primary key or columns inferred as primary key are same across multiple records in the result set. EF uses internally identity map which requires that each uniquely identified record must reuse the same instance of the entity. So if you return three records from the database which have same unique identification for EF will return enumeration of three same instances representing the first record from the result set (more about identity map also here). The same behaviour is in Linq-to-sql's DataContext.

    0 讨论(0)
提交回复
热议问题