2010-09-05 37 views
1

我試圖通過的DomainService(異步)在上樣的代碼行加載實體:DomainContext負載

context.Load<Book>(
context.Books.Where(b => b.BookID == 1), 
(s, e) => 
{ 
    _book = e.Results; 
}, 
null); 

但我得到以下錯誤: 類型「SilverlightApplication1.Book」不能被用作類型參數泛型類型或方法'System.ServiceModel.DomainServices.Client.DomainContext.Load(System.ServiceModel.DomainServices.Client.EntityQuery,System.Action>,object)'中的'TEntity''。沒有從'SilverlightApplication1.Book'到'System.ServiceModel.DomainServices.Client.Entit的隱式引用轉換如何解決它?

回答

4

你需要使用EntityQuery,看看你的堆棧跟蹤它是給的解決方案。

實現方法 'GetBookById' 在你的DomainService(在服務器上):

public IQueryable GetBookById(int Id)
{
return this.ObjectContext.Book.Where(r => r.Id == Id);
}

,然後加載這樣的數據:

EntityQuery query = context.GetBookByIdQuery(1);
context.Load(query, OnBookLoaded, null);

private void OnBookLoaded(LoadOperation lo)
{
// DO WITH DATA WHAT YOU NEED, NOTE: USE 'lo.Entities' there is loaded data
}