RIA 服务 - 分页

发布于 2024-08-30 06:57:21 字数 2415 浏览 1 评论 0原文

我正在测试 RIA 服务。我组合了一个 RIA 服务库并构建了一个自定义 DomainService(即不是实体框架域服务)。我正在从 Silverlight 应用程序访问该库,一切都按预期工作。我可以调用 RIA 服务功能并获取结果。

我的问题是分页。我在任何地方都找不到在使用自定义域服务的 RIA 服务上使用分页的描述。我的 RIA 服务正在访问专门的 DAL 来访问数据(并且与实体框架不兼容)。我发现将分页参数(即页面、页面大小)传递给 RIA 服务功能的指示。所以我就这么做了 - 创建了一个 RIA 服务函数,它采用页面 [index] 和页面大小的附加参数。我正在 Silverlight 中使用 DataGrid 和 DataPager 对此进行测试。调用带有分页参数的 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)

所以;我的问题是 - 有没有人看到这种行为 - 或者我犯了一个可怕的错误 - 如果是的话我做错了什么?

彼得

I am testing out RIA services. I put together a RIA Services library and built a custom DomainService (i.e. not an Entity Framework Domain Service). I am accessing the library from a Silverlight app and all is working as expected. I can call the RIA service functions and get the results.

My issue is with pagination. I cannot find anywhere a description of using pagination on a RIA service that uses custom domainServices. My RIA Service is accessing a specialized DAL for access to data (and is not compatible with the Entity Framework). What I have found was an indication to pass the pagination parameters (i.e. page, page size) to a RIA Service function. So I have done just that - created a RIA service function that takes additional parameters for Page [index] and Page size. I am testing this in Silverlight using a DataGrid and a DataPager. The RIA service with the pagination parameters is called (and returns data) and the DataGrid is populated. The problem I'm having is when I go to another page. What is occurring is the RIA service is called twice. The first time with the proper params (i.e. correct page index) then again with a page index of zero). I.e. always resets to first page. I don't understand why this is occurring; I believe I put everything together properly (hopefully). The following is the XAML script:

<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>

I have modified the above script to call the general loading function (GetPagedScheduleTemplates - returns all records) and adjusted the QueryParameters list for the function. The DataGrid loads properly - and pagination works properly.

This confused me - it sort of looked like the DataPager required all data to be loaded in order for it to work properly - but I did a test where I loaded all data on a paged request operation; (i.e. pagination properties setup and calling pagination version of RIA service function) but DataGrid still resets.

Note: I had read that the DataPager requires the return list to be ordered - so I did so - but did not affect operation - paging always reset to page 1 - the following is the return list from the RIA service function
newList.ToArray().AsQueryable().OrderBy(x=>x.ScheduleTemplateID)

So; my question is - has anyone seen this behavior - or am I making a horrendous mistake - if so what am I doing wrong?

Peter

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

萌面超妹 2024-09-06 06:57:21

一旦我集成了我上面提到的 Legecay DAL 库,一切就正常工作了。查看该库 - 它很容易使用(但需要进行一些阅读/回顾才能跟上它的速度)。还要确保您的 RIA 服务已正确配置为分页。根据我的阅读和发现 - 在寻呼机和域数据源中设置页面大小是正确操作所必需的。 ria 服务调用还需要一个计数操作(对于特定的实体对象),该操作也返回最大记录计数(如果不这样做,那么可能会发生像您提到的那样的事情 - 域数据源不知道要分页的总记录数) through - 所以它可能只是从头开始,因为它没有足够的信息——这通常很明显,因为寻呼机不会显示正确的最大页数,或者会显示最大页数 1 或 0)。

彼得

Once I integrated the Legecay DAL library I mentioned above all was working properly. Review the library - it is easy to use (but there is some reading/review to get up to speed with it). Also make sure your RIA service is properly configured for pagination. From what I have read and found - setting a page size in the pager and domain data source is required for proper operation. The ria service call also requires a count operation (for the specific entity object) also that return the MAX record count (if this is not done then things like you mention may occur -- the domain data source does not know the total records to paginate through -so it may just go the beginning because it does not have enough info -- this is usally apparent because the pager will not show the proper max page count or will show 1 or zero for the max page).

Peter

孤云独去闲 2024-09-06 06:57:21

好吧——这需要一些调查。我不知道 Ria 服务的一些限制以及如何与客户进行沟通。据我所知,分页信息通过基于 linq 的操作传递到 ria 服务。我对这个级别的 Ria 服务不太了解,但我发现有人做了一些很好的工作,将一个库组合在一起,通过自定义 DomainService 公开分页信息。该图书馆位于:
http://riatodal.codeplex.com/

有关谁以及如何使用该库的信息:
ryanmwright.com/tag/ria-services

该库用于更通用的内容,但重点关注 MS 提供的 Ria DomainServices 的分页限制。

彼得

Ok -- well this took some investigation. I was not aware of some of the limitations of Ria Services and how communication occurs with the client. From what I've found out the pagination information is xfered to the ria service via linq based operations. I'm not too up on Ria services at this level but I've found someone who has done some nice work to put together a library that exposes the pagination information via a custom DomainService. The library is available at:
http://riatodal.codeplex.com/

Info on who and how to use the library:
ryanmwright.com/tag/ria-services

This library is meant for something more general but focuses on the pagination restrictions with the supplied Ria DomainServices from MS.

Peter

银河中√捞星星 2024-09-06 06:57:21

嗯,看起来你做了一些令人困惑的事情。我认为您已经加倍了分页逻辑,并且您在服务器上手动分页,并且在客户端上有域数据源控制分页。

您已将 LoadSize 属性设置为 20。这告诉 RIA 服务您希望一次分页浏览 20 个记录块中的数据。因此,如果底层域操作 ddsScheduleTemplates 返回 50 条记录,您将获得三个页面,域数据源控件将自动附加 .Take(20).Skip(##) 一次将结果集过滤为一页。

但是,您似乎还向域操作添加了参数以支持分页,因为您有 PagePageSize 参数。我假设如果您传入 Page=2PageSize=20 ,则您将附加 .Skip(40).Take(20) 在服务器上的 Linq 查询中。如果是这种情况,那么域数据源控件将认为只有 20 条记录,因为这是您的操作将返回的最多记录。因此,只有一页。

如果这没有帮助,请发布您的服务器端域操作的代码,我将看看是否可以为您解决问题。

Well, it looks like you have done something confusing. I think you have doubled up on your paging logic and you are manually paging on the server and you have the Domain Datasource Control paging on the client.

You have set the LoadSize attribute to 20. This tells RIA Services that you want to page through the data in blocks of 20 records at a time. So, if the underlying domain operation ddsScheduleTemplates returns 50 records, you will get three pages and the Domain Datasource Control will automatically append .Take(20) and a .Skip(##) to filter down the result set to only one page at a time.

However, it also appears that you have added parameters to your domain operation to support paging because you have parameters for Page and PageSize. I assume that if you pass in Page=2 and PageSize=20 that you are appending a .Skip(40) and a .Take(20) in your Linq query on the server. If this is the case, then the Domain Datasource Control will think that there are only 20 records because that is the most your operation will return. So, there would be only one page.

If that doesn't help, then post the code for your server-side domain operation and I will see if I can route out the problem for you.

神经大条 2024-09-06 06:57:21

正在做的事情与我试图解决的问题相关。正如我提到的,我正在使用自定义 DomainService,因为我需要使用旧版 DAL。我不知道如何让分页工作 - 我读过的一个建议是提供自定义分页参数作为查询参数。这效果不太好 - 实际上一点也不 - 可能是因为缺少 PageSize - 但认为如果进行自定义分页,这可能不需要。

正如我在之前的评论中提到的(经过研究),我发现了一个不错的库,它允许将遗留 DALS 合并到 DomainService 中,并提供 MS RIA 提供的实体框架域服务中的逻辑。这解决了我的问题。

What was being done was related to the issue I was trying to resolve. As I mentioned I am using a custom DomainService because I was required to work with a legacy DAL. I could not figure out how to get things to work with respect to pagination - one suggestion I had read was to supply custom paging params as query params. This did not work too well - actually not at all - may be because of the missing PageSize - but thought that this may not be required if doing custom paging.

With all that said as I mentioned in my previous comment (after research) I had found a nice library that allows the incorporation of legacy DALS into a DomainService and provides the logic as found in the MS RIA supplied Entity Framework domain services. That solved my problem.

美男兮 2024-09-06 06:57:21

我和你有同样的问题。如果直接转到页面 X 会发生什么? Datapager 返回第 1 页?对我来说,如果我直接进入某个页面,一切都很好,但如果我点击下一页或上一页,它就会转到第 1 页。

I have the same issue that you. What is happen if you go directly to page X ? Datapager returns to page 1 ? For me, if I go directly to some page , everything is Ok, but if I click on next or previous its goes to page 1.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文