开发者

DomainContext Load

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 'S开发者_如何学JAVAilverlightApplication1.Book' to 'System.ServiceModel.DomainServices.Client.Entit

how to fix it?


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
}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜