2

我有这个工作和获取数据。但是,每次我翻页时,它都会调用 GetAllWebExceptions,它会从数据库中获取所有 Web 异常记录。分页应该如何实现?我只看过 EntityFrameworks 的例子。有没有人有一个使用 POCO 的数据源的好例子,或者还有吗?

 <Grid x:Name="LayoutRoot" Background="White">
        <ria:DomainDataSource x:Name="ErrorLogDataSource" 
                              LoadMethodName="GetAllWebExceptions">
            <ria:DomainDataSource.DomainContext>
                <services:CMSContext />
            </ria:DomainDataSource.DomainContext>
        </ria:DomainDataSource>
        <data:DataGrid x:Name="DataGridExceptions" ItemsSource="{Binding ElementName=ErrorLogDataSource, Path=Data}" 
                       AutoGenerateColumns="True">
        </data:DataGrid>
        <dataControls:DataPager Source="{Binding Data, ElementName=ErrorLogDataSource}" 
                                PageSize="20" />

在服务中:

[查询(PreserveName = true)]
公共 IEnumerable GetAllWebExceptions()
{
   返回 WebException.SelectAll("DATECREATED DESC");
}
4

2 回答 2

1

您当然应该能够使用 POCO 类。但是,您的查询方法需要通过返回一个通用的 IEnumerable 来引用它,因此系统的其余部分在编译时就知道您的类型。

要求是您的 POCO 类必须具有某种身份概念,由一个或多个标有 [Key] 元数据属性的成员组成。

例如:

public class WebException {

    [Key]
    string id;
    // Or it could be a DateTime if you use time of occurrence as the key,
    // or anything else that is unique.

    // ...
    // Other members
}

public class ErrorManager : DomainService {

    public IEnumerable<WebException> GetAllWebExceptions() {
        return WebException.SelectAll("DATECREATED DESC");
    }
}

希望有帮助...

于 2009-07-19T19:45:55.020 回答
0

看看 Brad Abrams将 POCO 与 RIA 服务结合使用的出色演练

于 2009-08-27T18:50:44.697 回答