I have a WCF Data Services service and its methods return Queryable lists.
Using a Java library, I could consume it with client-side paging (using top
and take
).
Now I intend to consume it with an UWP application.
Unfortunately the following code does not work:
var result = client.CreateQuery<Information>("GetInformation")
.AddQueryOption("id", string.Format("'{0}'", actualId))
.Skip(index)
.Take(amount).ToList();
I get this exception:
This target framework does not enable you to directly enumerate over a data service query. This is because enumeration automatically sends a synchronous request to the data service. Because this framework only supports asynchronous operations, you must instead call the BeginExecute and EndExecute methods to obtain a query result that supports enumeration.
As I had to use BeginExecute
, I can no longer use Skip
and Take
.
var query = client.CreateQuery<Information>("GetInformation")
.AddQueryOption("id", string.Format("'{0}'", actualId));
query.BeginExecute((x) =>
{
var result= query.EndExecute(x);
foreach (var information in result)
{
};
}, null);
How should I do it with this asynchronous method?
I was having the same problem but with OData. I found the solution in the next blog http://jqyblogger.blogspot.com/2013/11/linq-query-error-message-on-windows.html and basically we need to use the asyncronus tools for OData.
Default.Container context = new Default.Container(new Uri("url_to_OData_Service"));
var nquery = context.Reports
.Where(r => r.ReportId == 1)
.Select(p => p);
DataServiceQuery<Report> query = (DataServiceQuery<Report>)nquery;
TaskFactory<IEnumerable<Report>> taskFactory = new TaskFactory<IEnumerable<Report>>();
IEnumerable<Report> result = await taskFactory.FromAsync(query.BeginExecute(null, null), iar => query.EndExecute(iar));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.