I have one specific view created in my DB(joins about 5-6 tables with a left join).This view is added to my edmx (entity framework 1.0) . Recently I noticed that one of the
The problem is in fact with the key. You have to a) have a unique identifier for each row in the view. and b) map that key accordingly in the edmx. Otherwise as your quote states, the mapping logic will see each subsequent row and figure that it can use the same object instance that it returned before
Same problem for me.
An Entity View (VReport
) was generated automatically from VS2010 wizard to something like:
class VReport
Line: int (key)
Desc: string
Date: DateTime
When I retrieved the records from the database, the SQL query was formed correctly and returned the expected (and distinct) results, but the Entity Framework instead returned a lot of duplicated records.
But instead, also the Date column/field would have to partecipate in the formation the Entity KEY
So, to resolve this issue, I changed the property of the field from Entity Key: false -> true
class VReport
Line: int (key)
Desc: string
Date: DateTime (key)