I'm trying to page a data set in a WPF application.
My service method looks like this:
public ObservableCollection<MyModel> GetPageOfModels(int projectId, int numSkip, int numResults)
{
this.db.Set<MyModel>()
.Where(x => x.Project.Id == projectId)
.OrderBy(x => x.Name)
.Skip(numSkip)
.Take(numResults)
.Load();
return this.db.Set<MyModel>().Local;
}
This works great the first time it is hit. But when I move to a different page, Load()
is adding the next page to the set, rather than replacing it.
If I recreate the data context before each call to GetPageOfModels
it works, but I need to keep the same data context. Is there any way to achieve this?