1

我试图通过 domainservice(async) 在代码行中加载实体,例如:

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”中的类型参数“TEntity” , System.Action>, 对象)'。没有从“SilverlightApplication1.Book”到“System.ServiceModel.DomainServices.Client.Entit”的隐式引用转换

如何解决?

4

1 回答 1

4

你需要使用 EntityQuery,看看你的堆栈跟踪它是给解决方案。

在您的 DomainService(在服务器上)实现方法“GetBookById”:

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

然后像这样加载数据:

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

private void OnBookLoaded(LoadOperation lo)
{
// 使用您需要的数据,注意:使用 'lo.Entities' 加载数据
}

于 2010-09-07T19:28:45.920 回答