Skip to content

OData filter on 2nd level nested property System.InvalidOperationException could not be translated #23135

New issue

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

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

Already on GitHub? # to your account

Closed
adixon501 opened this issue Oct 29, 2020 · 2 comments · Fixed by #26324

Comments

@adixon501
Copy link

adixon501 commented Oct 29, 2020

Information

I have a Blazor WASM hosted app that uses OData to read data from the server. I am getting an error an error when trying to filter on a 2nd level property.

I have seen this issue raised a couple of times and both of them are closed and the fixes incorporated in the latest release.

Edit

In my full project (not the repo below), I have other 2nd level entities that use a Guid as an Id. When they are filtered using the same method mentioned below, it works. So it appears that it is having an issue filtering int 2nd level properties.

Steps to reproduce

link to repo

  1. Clone or download the above repo
  2. Set the Server project as the startup project and run
  3. Using Postman or a new browser tab, run the following odata query
    • https://localhost:5001/odata/Courses?$count=true&$expand=Instructor&$filter=Instructor/Id in (1)
  4. Observe the stacktrace in the response body

For added insight, a very similar query works great

  1. Use the following similar query
    • https://localhost:5001/odata/Courses?$count=true&$expand=Instructor&$filter=Instructor/Name in ('Mr. Smith')

Stack trace

System.InvalidOperationException: The LINQ expression 'DbSet<Course>
    .LeftJoin(
        outer: DbSet<Instructor>, 
        inner: c => EF.Property<Nullable<int>>(c, "InstructorId"), 
        outerKeySelector: i => EF.Property<Nullable<int>>(i, "Id"), 
        innerKeySelector: (o, i) => new TransparentIdentifier<Course, Instructor>(
            Outer = o, 
            Inner = i
        ))
    .LongCount(c => (IEnumerable<Nullable<int>>)<CastIterator>d__63<Nullable<int>> { 1, }
        .Contains((Nullable<int>)c.Inner.Id))' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync().

Provider Information

EF Core version: 3.1.9
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .Net Core 3.1
Operating system: Windows 10 Enterprise 1903
IDE: Visual Studio Professional 2019 16.7.3

@maumar
Copy link
Contributor

maumar commented Sep 14, 2021

depends on #25262, moving to MQ

@maumar
Copy link
Contributor

maumar commented Oct 6, 2021

works in current bits

maumar added a commit that referenced this issue Oct 13, 2021
maumar added a commit that referenced this issue Oct 13, 2021
maumar added a commit that referenced this issue Oct 13, 2021
maumar added a commit that referenced this issue Oct 13, 2021
@ghost ghost closed this as completed in #26324 Oct 13, 2021
ghost pushed a commit that referenced this issue Oct 13, 2021
@ajcvickers ajcvickers modified the milestones: MQ, 7.0.0 Oct 18, 2021
@ajcvickers ajcvickers modified the milestones: 7.0.0, 7.0.0-preview1 Feb 14, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0-preview1, 7.0.0 Nov 5, 2022
This issue was closed.
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants