Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: batch + linq not working #2409

Open
FrankTaubert opened this issue May 13, 2022 · 1 comment · May be fixed by #2475
Open

client: batch + linq not working #2409

FrankTaubert opened this issue May 13, 2022 · 1 comment · May be fixed by #2475

Comments

@FrankTaubert
Copy link

I can't use LINQ query with ExecuteBatch.
ExecuteBatch requires a DataServiceRequest as parameters, but constructing a query results in a IQueryable.

Assemblies affected

7.11

Reproduce steps

var request1 = context.SomeObject.Select( o => o.HasInterestingProperty)
var request2 = context.SomeAuxiliaryData.Select( o => o.HasSomeOtherProperty)

var batchResponse = context.ExecuteBatch(request1 , request2 );

Expected result

Compiles

Actual result

error: error CS1503: Argument 1: cannot convert from 'System.Linq.IQueryable<...>' to 'Microsoft.OData.Client.DataServiceRequest'

Additional detail

I want to request auxiliary data for a bunch of objects. That data is scattered over multiple endpoints, so a batch request will speed up the requests.
I know I can use AddQueryOption, but that is missing all the nice type checking.

@corranrogue9
Copy link
Contributor

@FrankTaubert, something is a little off with the code snippet, but I think I understand what you're getting at. You have something like:

DataServiceContext context;
...
var queryable = context.CreateQuery(...).Select(o => o.Foo);
...

and you want to later call:

context.ExecuteBatch(queryable, ...);

right? This does seem pretty annoying. What you can do to maintain type checking is construct the DataServiceRequests yourself. So, you end up with a bunch of IQueryable<T>, and you can do:

context.ExecuteBatch(
  new DataServiceQuery<T>(firstQueryable.Expression, new DataServiceQueryProvider(context)),
  new DataServiceQuery<U>(secondQueryable.Expression, new DataServiceQueryProvider(context)),
  ...);

Please try that and let me know if it helps. I'm also looking at what updates we can make to the library so that this flows more naturally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants