域上下文加载

发布于 2024-09-18 10:51:24 字数 496 浏览 14 评论 0原文

我尝试通过域服务(异步)在如下代码行中加载实体:

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

如何修复?

I tried to load a entity by domainservice(async) in on line of code like:

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

But I got following error:
The type 'SilverlightApplication1.Book' cannot be used as type parameter 'TEntity' in the generic type or method 'System.ServiceModel.DomainServices.Client.DomainContext.Load(System.ServiceModel.DomainServices.Client.EntityQuery, System.Action>, object)'. There is no implicit reference conversion from 'SilverlightApplication1.Book' to 'System.ServiceModel.DomainServices.Client.Entit

how to fix it?

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

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

发布评论

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

评论(1

海夕 2024-09-25 10:51:24

您需要使用 EntityQuery,查看您的堆栈跟踪,它给出了解决方案。

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

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

像这样加载数据:

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

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

you neet to use EntityQuery, look at your stack trace it is give solution.

implement method 'GetBookById' at your DomainService (at the server):

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

And then load data like this:

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
}

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