I have an ASP.NET web application which uses EF4. I have a page with an EntityDataSource that filters records from a SQL Server view. There is a GridView bound to my EntityDataSource to display the view records.
I’ve used this approach on many pages where the EntitySet associated with the EntityDataSource is linked to a SQL server table. I’m trying now for the first time to use an EntitySet that is bound to a SQL view.
The EntityDataSource returns the correct number of rows, depending on the where clause parameters.
However, each row returned from the EntityDataSource is exactly the same.
I’ve debugged the GridView’s RowDataBound event and confirmed that every row being bound has exactly the same content each time.
Something that is interesting is that when you page back or forth, the record being repeated changes. I’m guessing that somehow the first (or last?) record in any given page is the one that’s being repeated.
This feels like a bug in EF or the EntityDataSource. Has anyone seen this kind of behaviour before or do you have any advice around how to troubleshoot it?
I’ve seen this happen in other scenarios when the entity’s key property(ies) that come back from the view are not unique. EF will end up only materializing a single entity and thus the problem.
Are you sure the properties marked as entity keys are unique within the view?