JimFoye wrote:
The grid filter really doesn't have anything to do with this. It's true that one of two instances when the problem is reproduced is when I use the grid's filter, but the other is when I page, so we can safely ignore the filtering case, if that's helpful, and just say the following:
The Devex grid is not caching data, it has to ask the datasource control for the data (all of it) every time. So when I go to page 2 in the grid, the callback happens, and the grid asks the control for the data, and the datasource control then sends another query to the db, but this query does not contain the WHERE clause that it should. It then informs the grid that there are 7574 records, and the grid proceeds to operate on that assumption. But EntityCollection still only contains 7200 records. Problems result.
I posted some posts back a test where I couldn't reproduce this, of course that weird setting devexpress has on their grid has to be true, otherwise it indeed fetches all the data (in short: it simply tells the datasource control to get all the data).
So I'm a bit confused what the grid setup is that you're using. This isn't your fault but I can't fix problems which are popping up because some control vendors thinks their grouping stuff is 'superior' and therefore has to fetch every row in the DB...
It now occurs to me that there's another funny thing about this second query. Unless I specify CacheLocation is None, doesn't the datasource control already have the data and not need to send the query to the db at all?
That's true, however it determines if it has to fetch things again or not, based on the input it gets from the grid and for example SelectParameter filters. If things haven't changed, it simply returns the same set.
This is not my area of expertise, obviously, but I was just looking at the base classes and interfaces for the data source control. I would have thought IDataSource was the magic interface, but I don't see any methods there to get data. It seems like ultimately the grid would be calling IListSource.GetList() to get the data? That returns a list, not a count, and leaves the control to return the data however it likes (such as from its own cache). I don't see some other method that could inconsistently be returning a count that's different from what's returned by GetList(), nor anything the grid could be calling like GoToTheDatabaseWithNoFilterAndTellMeTheCountIDontCareWhatDataYouHaveCachedOrFilterYouAreUsing(), though admittedly that would be a pretty long API name.
Datasource controls work with 2 objects: The DataSourceControl derived object and a DataSourceView derived object. The DataSourceControl object is bound to the grid. this is really a dumb object, as it leaves everything to the view. The grid asks the datasourcecontrol for its DataSourceView instance and calls ExecuteSelect on that view. The DataSourceView has to figure out based on what it has read from the viewstate and the input parameters what it should do: fetch everything or return what it already has. This is a difficult task, as it has to figure out that the input parameters it receives plus other info is equal to the elements it used to fetch the previous set. If it decides it's not the same, it starts a refetch.
It's now a question if this happens in your case or not. As I posted before, I couldn't reproduce it with 9.1.2.