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

EF core 3 global query filter cannot translate contain expression #18465

Closed
dimz87 opened this issue Oct 19, 2019 · 6 comments
Closed

EF core 3 global query filter cannot translate contain expression #18465

dimz87 opened this issue Oct 19, 2019 · 6 comments

Comments

@dimz87
Copy link

dimz87 commented Oct 19, 2019

In the EF Core version 2.2 i can create a query filter with contain as the filtering expression, in the version 3.0 it will throw exception that showing it cannot be translated.

Steps to reproduce

In the db context class create an entity with query filter

protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
          
            base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Company>().HasQueryFilter(c =>
          _companyCodes.Contains(c.Code));
}

The filter will always produce exception:

The LINQ expression 'Where<Company>( source: DbSet<Company>, predicate: (c) => (Unhandled parameter: __ef_filter__p_0) || (Unhandled parameter: __ef_filter___companyCodes_1).Contains(c.Code))' 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(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.

As it is located in the queryfilter i cannot use asasyncenumberable or to list, how to mitigate this issue in ef 3 ?

Further technical details

EF Core version: 3.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET Core 3.0
Operating system: Windows 10
IDE: Visual Studio 2019 16.3.5

@dimz87 dimz87 changed the title Global query filter cannot translate contain EF core 3 global query filter cannot translate contain expression Oct 19, 2019
@smitpatel
Copy link
Contributor

What is the type of _companyCodes?

@dimz87
Copy link
Author

dimz87 commented Oct 20, 2019

The _companyCodes type is List<string>

@smitpatel
Copy link
Contributor

Could be duplicate of #17342
Can you try running with 3.1-preview1 package?

@dimz87
Copy link
Author

dimz87 commented Oct 21, 2019

Putting List<string> into ICollection<string> or IList<string> causing this issue, i can confirm on version 3.1 preview using List<string> directly the problem solved.

@smitpatel
Copy link
Contributor

@dimz87 - can you share a small repro code which demonstrate the issue?

@dimz87
Copy link
Author

dimz87 commented Oct 21, 2019

@dimz87 - can you share a small repro code which demonstrate the issue?

Sorry, i have clarify my comment, pleas see my comment

@dimz87 dimz87 closed this as completed Oct 21, 2019
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
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