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

Using LINQ to perform various query operations on dynamic properties not supported in OData Client #3044

Open
ElizabethOkerio opened this issue Aug 23, 2024 · 4 comments

Comments

@ElizabethOkerio
Copy link
Contributor

ElizabethOkerio commented Aug 23, 2024

When using the OData client, attempting to filter and select values from a dictionary of dynamic properties within a LINQ query results in an error or unexpected behavior. Specifically, the following pattern is not supported:

var middleName = _context.Accounts
    .Where(a => a.AccountID == 101)
    .Select(a => a.AccountInfo.DynamicProperties.Where(dp => dp.Key == "MiddleName").Single());

Assemblies affected

Microsoft.OData.Client 8.x.

Reproduce steps

The simplest set of steps to reproduce the issue. If possible, reference a commit that demonstrates the issue.

Expected result

The OData client should correctly translate the LINQ query into an OData request, filtering the DynamicProperties dictionary for the specified key ("MiddleName") and returning the corresponding value.

Actual result

What is actually happening.
An error gets thrown: Error translating Linq expression to URI: Can only specify query options (orderby, where, take, skip) after last navigation

Additional detail

Optional, details of the root cause if known. Delete this section if you have no additional details to add.

@ElizabethOkerio ElizabethOkerio changed the title Using LINQ to perform the various query operations on dynamic properties not supported in OData Client Using LINQ to perform various query operations on dynamic properties not supported in OData Client Aug 23, 2024
@corranrogue9
Copy link
Contributor

Is the intent to generate a query like GET /accounts/101?$select=AccountInfo/MiddleName? I don't think the syntax of .Select(a => a.AccountInfo.DynamicProperties.Where(dp => dp.Key == "MiddleName").Single()) is really a clear way for users to request that URL

@WanjohiSammy
Copy link
Contributor

@ElizabethOkerio Please provide sample URL that the example query is likely to translated to.

@WanjohiSammy
Copy link
Contributor

@ElizabethOkerio Provide examples/tests

@ElizabethOkerio
Copy link
Contributor Author

Is the intent to generate a query like GET /accounts/101?$select=AccountInfo/MiddleName? I don't think the syntax of .Select(a => a.AccountInfo.DynamicProperties.Where(dp => dp.Key == "MiddleName").Single()) is really a clear way for users to request that URL

How should users then request for this URL? If they are using the DynamicProperties container generated by OData Connected Service? If they want to select the open properties in the container.

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

No branches or pull requests

3 participants