使用DomainCollectionView和自定义DomainService无法正确显示分页项

时间:2011-07-13 20:26:40

标签: silverlight ria wcf-ria-services domainservices

我正在开发一个RIA服务应用程序,并且在服务器端分页和DataGrid中的分页项显示方面存在问题。我正在使用自定义DomainService,其中PageIndex& PageSize通过Query以及几个过滤器参数传递。

问题是我的第一页结果显示正确,但当我转到下一组结果时,我的项目被添加到列表的末尾而不是仅显示从服务器返回的新结果。即,我的DataGrid显示从服务器返回的所有累积对象,而不是仅显示返回的最新结果页。

首先,我正在使用DomainCollectionView和DomainCollectionViewLoader:


 _context = new StudyQueryContext();
_entityList = new EntityList(_context.PortalStudies);
_loader = new DomainCollectionViewLoader(Load, LoadComplete);
PortalStudies = new DomainCollectionView(_loader, _context.PortalStudies);      

然后我有相当标准的Load()和LoadComplete()方法:


public LoadOperation Load()
{
    if (IsLoading)
    {
        return null;
    }

    IsLoading = true;
    EntityQuery q = _context.GetPortalStudyQuery(PatientsName, PatientId, AccessionNumber, PortalStudies.PageIndex, PortalStudies.PageSize);           
    return _context.Load(q);
}

private void LoadComplete(LoadOperation op)
{
    if (op.HasError)
    {
        System.Windows.MessageBox.Show(op.Error.ToString(), "Search Error", System.Windows.MessageBoxButton.OK);
        op.MarkErrorAsHandled();
    }
    else if (!op.IsCanceled)
    {
        _entityList.Source = op.Entities;
        _context.PortalCountAll(PatientsName, PatientId, AccessionNumber, CountAllComplete, null);
    }

    IsLoading = false;
}

请注意,我在PortalCountAll方法返回时分配TotalItemCount。

为了完整起见,我的DomainService Query方法的签名如下:


[Query]
public IEnumerable<PortalStudy> GetPortalStudy(string patientsName, string patientId, string accessionNumber, int startIndex, int pageSize)
{ }  

我认为问题在于我如何设置_entityList以及在LoadComplete()方法中分配结果:

_entityList.Source = op.Entities;  

似乎在所有基于LINQ的示例中,此赋值似乎只允许在DataGrid中显示当前结果。出于某种原因,使用自定义查询方法时似乎并非如此。

我想知道更改页面时清除DataGrid的首选方法是什么?我知道我可以在查询之前调用_context.PortalStudies.Clear()来清除结果,但是这会导致页面上的闪存清除,并且在查询从服务器返回之前不会再次填充。使用自定义DomainService时,仅显示当前结果页面的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

使用不支持LINQ的自定义ORM时,您可以(并且应该)传递PageIndex和PageSize。它允许您针对ORM进行分页,但也会使分页稍微复杂化。您需要override DomainService.Countadd a totalCount out parameter

但是,在您的情况下,看起来好像是您已将EntitySet(_context.PortalStudies)传递给DCV构造函数而不是EntityList(_entityList)。