Open ChrisJollyAU opened 1 month ago
Bit more info on this
Its actually part of the shaper created in RelationalShapedQueryCompilingExpressionVisitor
(under EFCore.Relational\Query
)
It is part of the function CreateGetValueExpression
When you have detailed erros enabled you have the following block that executes of which it doesn't seem like the precompile undewrstands it yet
if (_detailedErrorsEnabled
&& !buffering)
{
var exceptionParameter = Parameter(typeof(Exception), name: "e");
var catchBlock = Catch(
exceptionParameter,
Call(
ThrowReadValueExceptionMethod.MakeGenericMethod(valueExpression.Type),
exceptionParameter,
Call(dbDataReader, GetFieldValueMethod.MakeGenericMethod(typeof(object)), indexExpression),
Constant(valueExpression.Type.MakeNullable(nullable), typeof(Type)),
_parentVisitor.Dependencies.LiftableConstantFactory.CreateLiftableConstant(
property,
LiftableConstantExpressionHelpers.BuildMemberAccessLambdaForProperty(property),
property + "Property",
typeof(IPropertyBase))));
valueExpression = TryCatch(valueExpression, catchBlock);
}
It is simple to recreate this issue - just add .EnableDetailedErrors()
to the builder
in AddProviderOptions
.
e.g. with Sqlite you will have
public virtual DbContextOptionsBuilder AddProviderOptions(
DbContextOptionsBuilder builder,
Action<SqliteDbContextOptionsBuilder>? configureSqlite)
=> builder.UseSqlite(
Connection, b =>
{
b.CommandTimeout(CommandTimeout);
b.UseQuerySplittingBehavior(QuerySplittingBehavior.SingleQuery);
configureSqlite?.Invoke(b);
}).EnableDetailedErrors();
I am busy adding the PrecompiledQuery functionality to EFCore.Jet provider including its test suite and have run into an error I'm not sure about
When running a test (e.g.
BinaryExpression
) inPrecompiledQueryJetTest
(outside of naming and such pretty much similar toPrecompiledQuerySqlServerTest
), I end up with the following errorIt obviously doesn't happen with Sql Server or Sqlite.
Debugging info This seems to have something to do with the Execution Strategy being used. When it uses the default
NonRetryingExecutionStrategy
it comes up with the above error. However if I use the retrying execution strategy (JetRetryingExecutionStrategy
orTestJetRetryingExecutionStrategy
) it works fine as expected.Further debugging brings me to the
CompileQuery
function within theProcessSyntaxTree
in this file https://github.com/dotnet/efcore/blob/main/src/EFCore.Design/Query/Internal/PrecompiledQueryCodeGenerator.cs#L188It is further in the
ProcessSyntaxTree
function when it callsGenerateQueryExecutor
that we get the error.Looking at the debug view of the
queryExecutor
variable we see the following difference (only relevant part shown - not the whole view) This is what I get with Sql Server and SqliteThis is what I get on EFCore.Jet
Note the part where the data reader call is wrapped in a try...catch. Not sure why it is being generated
As a further note, in the
VisitTry
function ofLinqToCSharpSyntaxTranslator
, the_context
variable that theswitch
is done on isExpressionContext.Expression
hence theNotImplementedException
I know its still marked as experimental so maybe I have hit something not finished yet
SDK: .Net 9 preview 6 Visual Studio: 17.11.0 preview 7 EF Core: 9.0.0-rc.1.24374.2 ( a daily build a day or 2 after the last preview 7 so should be close to what the final preview 7 release will be) Using the preview 6 branch of efcore to build and debug on the SQL Server and Sqlite for comparison
Any thoughts?