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 2.2 - cannot use Where operator #243

Closed
jakoss opened this issue Jan 28, 2019 · 2 comments
Closed

EF Core 2.2 - cannot use Where operator #243

jakoss opened this issue Jan 28, 2019 · 2 comments

Comments

@jakoss
Copy link

jakoss commented Jan 28, 2019

I have table Packages with OneToMany relationship with table PackageErrors. It's in model like this

public ICollection<PackageError> Errors { get; set; }

I'm trying to filter all Packages that have specific type of error. So i do query (ErrorType is enum, but it's no that relevant):

dbContext.Packages.Where("Errors.Where(ErrorType = \"AmountTooHigh\")");

Unfortunetely i get an exception:

No generic method 'Where' on type 'System.Linq.Queryable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic. 
   at System.Linq.Expressions.Expression.FindMethod(Type type, String methodName, Type[] typeArgs, Expression[] args, BindingFlags flags)
   at System.Linq.Expressions.Expression.Call(Type type, String methodName, Type[] typeArguments, Expression[] arguments)
   at System.Linq.Dynamic.Core.DynamicQueryableExtensions.Where(IQueryable source, ParsingConfig config, String predicate, Object[] args) in /DynamicQueryableExtensions.cs:line 1918
   at System.Linq.Dynamic.Core.DynamicQueryableExtensions.Where[TSource](IQueryable`1 source, ParsingConfig config, String predicate, Object[] args) in /DynamicQueryableExtensions.cs:line 1883
   at System.Linq.Dynamic.Core.DynamicQueryableExtensions.Where[TSource](IQueryable`1 source, String predicate, Object[] args) in /DynamicQueryableExtensions.cs:line 1889
   at Polly.Portal.Infrastructure.Sieving.Filtering.FilteringQueryParser.Apply[TEntity](IQueryable`1 query, String filteringQuery) in C:\Projects\Payground\PollyPortal\Polly.Portal.WebApi\Polly.Portal.Infrastructure\Sieving\Filtering\FilteringQueryParser.cs:line 11
   at Polly.Portal.Infrastructure.Sieving.SieveService.Apply[TEntity](IQueryable`1 query, SieveQuery sieveQuery) in C:\Projects\Payground\PollyPortal\Polly.Portal.WebApi\Polly.Portal.Infrastructure\Sieving\SieveService.cs:line 14
   at Polly.Portal.Packages.Features.CustomerList.Handler.Handle(Query request, CancellationToken cancellationToken) in C:\Projects\Payground\PollyPortal\Polly.Portal.WebApi\Polly.Portal.Packages\Features\CustomerList.cs:line 110

I don't have a clue where to look for probable cause.

@StefH
Copy link
Collaborator

StefH commented Jan 28, 2019

I guess you need code like:

var p = new[] { new Packages { Errors = new[] { new PackageError { ErrorType = "AmountTooHigh" }} } }.AsQueryable();
	var resultP = p.Where("Errors.Any(ErrorType = \"AmountTooHigh\") = true");

@jakoss
Copy link
Author

jakoss commented Jan 28, 2019

Ok, my bad, i was thinking about it the wrong way. Thanks, it works

@jakoss jakoss closed this as completed Jan 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants