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

AsSplitQuery not implemented on EF Core InMemory #22034

Closed
marianosz opened this issue Aug 12, 2020 · 9 comments · Fixed by #22098 or #22107
Closed

AsSplitQuery not implemented on EF Core InMemory #22034

marianosz opened this issue Aug 12, 2020 · 9 comments · Fixed by #22098 or #22107
Assignees
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-enhancement
Milestone

Comments

@marianosz
Copy link

Queries using the new 'AsSplitQuery' fail when using Memory Provider
Error: System.NotImplementedException : Unhandled method 'AsSplitQuery'.
I understand that this will have no effect on the memory " query ", but maybe there is a way to at least do nothing but don't throw an exception. (Like the AsNoTracking method) on Memory Provider

Steps to reproduce

Run any query using In Memory Context (EF Core InMemory) that contains a ' AsSplitQuery' method call.

System.NotImplementedException : Unhandled method 'AsSplitQuery'.
ERROR:
System.NotImplementedException : Unhandled method 'AsSplitQuery'.
STACK:
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass12_01.<ExecuteAsync>b__0() at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func1 compiler)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable1 source, Expression expression, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable1 source, LambdaExpression expression, CancellationToken cancellationToken)

Further technical details

EF Core version: 5.0.0-preview.7.20364.11
Database provider: Microsoft.EntityFrameworkCore.InMemory
Target framework: .NET Core 3.1
Operating system: Windows 10 / Ubuntu 20
IDE: Visual Studio 2019 16.3 / VS Code

@smitpatel
Copy link
Member

AsNoTracking actually has effect on InMemory provider. AsSplitQuery is plain wrong. Note if you are using only one provider in your code, (e.g. InMemory) then you won't even get method AsSplitQuery since it is defined only for relational providers.
If you are having multiple providers in your project then you need to conditionally do things which are provider specific, which applies to building model, query operators, database specific functions.

@roji
Copy link
Member

roji commented Aug 12, 2020

Better exception and message? NotImplementedException should generally not be exposed by any of our APIs...

@marianosz
Copy link
Author

marianosz commented Aug 12, 2020

Yeah I got it, but I have a business layer that I need to test, and all the test are having exceptions because of this... Looks really complicated and inadequate to add conditional logic on a business layer related the providers (maybe this method can be implemented to do nothing on the memory provider because memory provider is something a lot of devs use to create unit tests) If you have any other suggestion to use this without the need to inform the business layer about the provider that we are using, that will be awesome!

@smitpatel
Copy link
Member

smitpatel commented Aug 12, 2020

Better exception and message? NotImplementedException should generally not be exposed by any of our APIs...

Can throw InvalidOperationException instead. More than that, we cannot identify across provider if you used method from other provider. Same error would happen if you used EF.Functions.Collate or EF.Functions.DateTimeFromDateParts

@marianosz
Copy link
Author

yeah but EF.Functions.Collate or EF.Functions.DateTimeFromDateParts are really specific and it is fine to throw an error on memory provider, but AsSplitQuery is a global query modifier method to have the same behavior on the queries that we have on EF Core 2, an it will be common scenario to try to test code that will have this method to run common queries...

@ajcvickers
Copy link
Member

I think we should look at what we can do to make this better. Its conceptually similar to what we did to allow transactions to be a no-op when using the in-memory provider.

@marianosz
Copy link
Author

@ajcvickers that would be awesome, I understand that in memory provider that method will do nothing, but will be great for the Unit Test context! Thanks!

@ajcvickers
Copy link
Member

Decision from triage: no-op for the in-memory provider.

@marianosz
Copy link
Author

@ajcvickers awesome! Thanks!

@smitpatel smitpatel added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Aug 17, 2020
@smitpatel smitpatel modified the milestones: 5.0.0, 5.0.0-rc1 Aug 17, 2020
smitpatel added a commit that referenced this issue Aug 17, 2020
Manually verified
- Works for Relational
- No-op for InMemory
- Throws translation failure for Cosmos

Resolves #22034
@ghost ghost closed this as completed in #22098 Aug 17, 2020
ghost pushed a commit that referenced this issue Aug 17, 2020
Manually verified
- Works for Relational
- No-op for InMemory
- Throws translation failure for Cosmos

Resolves #22034
smitpatel added a commit that referenced this issue Aug 17, 2020
Manually verified
- Works for Relational
- No-op for InMemory
- Throws translation failure for Cosmos

Resolves #22034
ghost pushed a commit that referenced this issue Aug 18, 2020
Manually verified
- Works for Relational
- No-op for InMemory
- Throws translation failure for Cosmos

Resolves #22034
@ajcvickers ajcvickers modified the milestones: 5.0.0-rc1, 5.0.0 Nov 7, 2020
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-enhancement
Projects
None yet
4 participants