Skip to content
This repository was archived by the owner on Feb 1, 2025. It is now read-only.
This repository was archived by the owner on Feb 1, 2025. It is now read-only.

Support AsNoTrackingWithIdentityResolution #345

Closed
@warappa

Description

@warappa

Issue

I use Linq2DB.EntityFrameworkCore to do CTEs.

In one of them I switched from AsNoTracking() to AsNoTrackingWithIdentityResolution().
In my tests I now get an exception.

Exception

at LinqToDB.Linq.Builder.ExpressionBuilder.OptimizeExpressionImpl(HashSet`1 currentParameters, Expression expr) 
at LinqToDB.Expressions.TransformInfoVisitor`1.Transform(Expression expr) 
at LinqToDB.Linq.Builder.ExpressionBuilder.OptimizeExpression(Expression expression) 
at LinqToDB.Linq.Builder.ExpressionBuilder.ConvertWhere(MethodCallExpression method) 
at LinqToDB.Linq.Builder.ExpressionBuilder.OptimizeExpressionImpl(HashSet`1 currentParameters, Expression expr) 
at LinqToDB.Expressions.TransformInfoVisitor`1.Transform(Expression expr) 
at LinqToDB.Linq.Builder.ExpressionBuilder.OptimizeExpression(Expression expression) 
at LinqToDB.Linq.Builder.ExpressionBuilder.ConvertSelect(MethodCallExpression method) 
at LinqToDB.Linq.Builder.ExpressionBuilder.OptimizeExpressionImpl(HashSet`1 currentParameters, Expression expr) 
at LinqToDB.Expressions.TransformInfoVisitor`1.Transform(Expression expr) 
at LinqToDB.Expressions.TransformInfoVisitor`1.Transform[T](IList`1 source) 
at LinqToDB.Expressions.TransformInfoVisitor`1.Transform(Expression expr) 
at LinqToDB.Expressions.TransformInfoVisitor`1.Transform[T](IList`1 source) 
at LinqToDB.Expressions.TransformInfoVisitor`1.Transform(Expression expr) 
at LinqToDB.Expressions.TransformInfoVisitor`1.Transform[T](IList`1 source) 
at LinqToDB.Expressions.TransformInfoVisitor`1.Transform(Expression expr) 
at LinqToDB.Linq.Builder.ExpressionBuilder.OptimizeExpression(Expression expression) 
at LinqToDB.Linq.Builder.ExpressionBuilder.ConvertExpressionTree(Expression expression) 
at LinqToDB.Linq.Builder.ExpressionBuilder..ctor(Query query, ExpressionTreeOptimizationContext optimizationContext, ParametersContext parametersContext, IDataContext dataContext, Expression expression, ParameterExpression[] compiledParameters) 
at LinqToDB.Linq.Query`1.CreateQuery(ExpressionTreeOptimizationContext optimizationContext, ParametersContext parametersContext, IDataContext dataContext, Expression expr) 
at LinqToDB.Linq.Query`1.GetQuery(IDataContext dataContext, Expression& expr, Boolean& dependsOnParameters) 
at LinqToDB.Linq.ExpressionQuery`1.GetQuery(Expression& expression, Boolean cache, Boolean& dependsOnParameters) 
at LinqToDB.Linq.ExpressionQuery`1.System.Linq.IQueryProvider.Execute[TResult](Expression expression) 
...

Investigation

I think this is because only AsNoTracking is handled in this library:

static readonly MethodInfo AsNoTrackingMethodInfo = MemberHelper.MethodOfGeneric<IQueryable<object>>(q => q.AsNoTracking());

else if (generic == AsNoTrackingMethodInfo)
{
isTunnel = true;
tracking = false;
}

Expectation

It should not throw an exception, but just note down that this query is not tracked and move on like in the AsNoTracking() case.

Info

.NET SDK: 7.0.401
Linq2DB.EntityFrameworkCore: 7.5.0
Linq2DB: 5.2.1/5.2.2

PS

Just a note for if you experience something similary:
Weirdly, running my application and issuing the queries did not trigger this exception and thus completed successfully. I still don't know why, but I think it's releated to something else.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions