Efcore: AsSplitQuery not implemented on EF Core InMemory

Created on 12 Aug 2020  路  9Comments  路  Source: dotnet/efcore


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.CreateQueryExecutorTResult
at Microsoft.EntityFrameworkCore.Storage.Database.CompileQueryTResult
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCoreTResult
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.ExecuteAsyncTResult
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsyncTResult
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsyncTSource,TResult

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

area-query closed-fixed customer-reported type-enhancement

Most helpful comment

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.

All 9 comments

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.

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

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!

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

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...

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.

@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!

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

@ajcvickers awesome! Thanks!

Was this page helpful?
0 / 5 - 0 ratings