我正在测试RIA服务。我将RIA Services库放在一起,并构建了一个自定义的DomainService(即不是实体框架域服务)。我正在从Silverlight应用程序访问该库,并且所有工作都按预期工作。我可以调用RIA服务函数并获得结果。RIA服务 - 分页
我的问题是与分页。我无法在任何地方找到在使用自定义域名服务的RIA服务上使用分页的描述。我的RIA服务正在访问专门的DAL以访问数据(并且与实体框架不兼容)。我发现的是将分页参数(即页面,页面大小)传递给RIA服务功能的指示。所以我已经完成了 - 创建了一个RIA服务函数,它为Page [index]和Page size增加了额外的参数。我正在使用DataGrid和DataPager在Silverlight中进行测试。具有分页参数的RIA服务被调用(并返回数据)并填充DataGrid。我遇到的问题是当我去另一个页面。发生的是RIA服务被调用两次。第一次使用正确的参数(即正确的页面索引),然后再次使用页面索引为零)。即总是重置为第一页。我不明白为什么会发生这种情况;我相信我把所有的东西放在一起(希望)。以下是XAML脚本:
<riaControls:DomainDataSource
Name="ddsScheduleTemplates"
LoadSize="20"
QueryName="GetPagedScheduleTemplates"
AutoLoad="True"
>
<riaControls:DomainDataSource.DomainContext>
<ds:ScheduleEngineDomainContext/>
</riaControls:DomainDataSource.DomainContext>
<riaControls:DomainDataSource.QueryParameters>
<riaControls:Parameter ParameterName="UserLogonName" Value="admin" />
<riaControls:Parameter ParameterName="UserPassword" Value="admin" />
<riaControls:Parameter ParameterName="Page" Value="{Binding ElementName=dpScheduleTemplates, Path=PageIndex}" />
<riaControls:Parameter ParameterName="PageSize" Value="{Binding ElementName=dpScheduleTemplates, Path=PageSize}" />
</riaControls:DomainDataSource.QueryParameters>
</riaControls:DomainDataSource>
<StackPanel>
<dg:DataGrid
Name="ScheduleTemplatesGrid"
MinHeight="100"
MaxHeight="300"
IsReadOnly="True"
ItemsSource="{Binding ElementName=ddsScheduleTemplates, Path=Data}"
/>
<dg:DataPager
x:Name="dpScheduleTemplates"
PageSize="10"
Source="{Binding ElementName=ddsScheduleTemplates, Path=Data}"
PageIndexChanged="dpScheduleTemplates_PageIndexChanged"
/>
</StackPanel>
我已经修改了上面的脚本调用一般加载函数(GetPagedScheduleTemplates - 返回所有记录),并调整QueryParameters列表功能。 DataGrid正确加载 - 并且分页工作正常。
这使我困惑 - 它看起来像DataPager需要加载所有数据才能正常工作 - 但我做了一个测试,在加载页面请求操作中的所有数据; (即分页属性设置和调用RIA服务功能的分页版本),但DataGrid仍会重置。
注:我读过DataPager需要订购返回列表 - 我这样做 - 但不影响操作 - 分页始终重置为第1页 - 以下是RIA服务功能返回列表 newList.ToArray()。AsQueryable()。OrderBy(x => x.ScheduleTemplateID)
所以;我的问题是 - 有没有人看到过这种行为 - 或者我犯了一个可怕的错误 - 如果是的话,我做错了什么?
彼得
这将是伟大的,如果你littlebit格式化你的答案。 :) – 2012-12-04 08:56:04