2009-07-02 16 views
2

我有這個工作,並獲取數據。但是,每次我打開頁面時,都會調用GetAllWebExceptions,它從數據庫中獲取所有Web異常記錄。如何實現分頁?我只看到了EntityFrameworks的例子。有沒有人有與POCO一起使用數據源的好例子,還是還有未來?有沒有人有.NET RIA DomainDataService和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" /> 

在服務:

 
[Query(PreserveName = true)] 
public IEnumerable GetAllWebExceptions() 
{ 
    return WebException.SelectAll("DATECREATED DESC"); 
} 
+0

上silverlight.net論壇類似的問題:HTTP: //silverlight.net/forums/p/100818/244081.aspx#244081 – Aligned 2009-07-07 18:03:09

回答

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"); 
    } 
} 

希望幫助...

相關問題