Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from alexwiese/bugfix/cached-query
Fix issues where query was being cached, moved modifications up to....
- Loading branch information
Showing
6 changed files
with
137 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...penEdge/Query/ExpressionVisitors/Internal/OpenEdgeParameterExtractingExpressionVisitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Reflection; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Diagnostics; | ||
using Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal; | ||
using Microsoft.EntityFrameworkCore.Query.Internal; | ||
using Remotion.Linq.Parsing.ExpressionVisitors.TreeEvaluation; | ||
|
||
namespace EntityFrameworkCore.OpenEdge.Query.ExpressionVisitors.Internal | ||
{ | ||
public class OpenEdgeParameterExtractingExpressionVisitor : ParameterExtractingExpressionVisitor | ||
{ | ||
public OpenEdgeParameterExtractingExpressionVisitor(IEvaluatableExpressionFilter evaluatableExpressionFilter, | ||
IParameterValues parameterValues, | ||
IDiagnosticsLogger<DbLoggerCategory.Query> logger, | ||
DbContext context, | ||
bool parameterize, bool | ||
generateContextAccessors = false) | ||
: base(evaluatableExpressionFilter, parameterValues, logger, context, parameterize, generateContextAccessors) | ||
{ | ||
} | ||
|
||
protected Expression VisitNewMember(MemberExpression memberExpression) | ||
{ | ||
if (memberExpression.Expression is ConstantExpression constant | ||
&& constant.Value != null) | ||
{ | ||
switch (memberExpression.Member.MemberType) | ||
{ | ||
case MemberTypes.Field: | ||
return Expression.Constant(constant.Value.GetType().GetField(memberExpression.Member.Name).GetValue(constant.Value)); | ||
|
||
case MemberTypes.Property: | ||
var propertyInfo = constant.Value.GetType().GetProperty(memberExpression.Member.Name); | ||
if (propertyInfo == null) | ||
{ | ||
break; | ||
} | ||
|
||
return Expression.Constant(propertyInfo.GetValue(constant.Value)); | ||
} | ||
} | ||
|
||
return base.VisitMember(memberExpression); | ||
} | ||
|
||
protected override Expression VisitNew(NewExpression node) | ||
{ | ||
var memberArguments = node.Arguments.OfType<MemberExpression>().Select(VisitNewMember).ToList(); | ||
|
||
var arguments = Visit(node.Arguments.Where(a => !(a is MemberExpression)).ToList().AsReadOnly()); | ||
|
||
var newNode = node.Update(memberArguments.Concat(arguments)); | ||
|
||
return newNode; | ||
} | ||
|
||
protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression) | ||
{ | ||
if (methodCallExpression.Method.Name == "Take") | ||
{ | ||
return methodCallExpression; | ||
} | ||
|
||
if (methodCallExpression.Method.Name == "Skip") | ||
{ | ||
return methodCallExpression; | ||
} | ||
|
||
return base.VisitMethodCall(methodCallExpression); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/EFCore.OpenEdge/Query/Internal/OpenEdgeQueryModelGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Linq.Expressions; | ||
using EntityFrameworkCore.OpenEdge.Query.ExpressionVisitors.Internal; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Diagnostics; | ||
using Microsoft.EntityFrameworkCore.Internal; | ||
using Microsoft.EntityFrameworkCore.Query.Internal; | ||
using Remotion.Linq.Parsing.ExpressionVisitors.TreeEvaluation; | ||
|
||
namespace EntityFrameworkCore.OpenEdge.Query.Internal | ||
{ | ||
public class OpenEdgeQueryModelGenerator : QueryModelGenerator | ||
{ | ||
private readonly IEvaluatableExpressionFilter _evaluatableExpressionFilter; | ||
private readonly ICurrentDbContext _currentDbContext; | ||
|
||
public OpenEdgeQueryModelGenerator(INodeTypeProviderFactory nodeTypeProviderFactory, | ||
IEvaluatableExpressionFilter evaluatableExpressionFilter, | ||
ICurrentDbContext currentDbContext) | ||
: base(nodeTypeProviderFactory, evaluatableExpressionFilter, currentDbContext) | ||
{ | ||
_evaluatableExpressionFilter = evaluatableExpressionFilter; | ||
_currentDbContext = currentDbContext; | ||
} | ||
|
||
public override Expression ExtractParameters(IDiagnosticsLogger<DbLoggerCategory.Query> logger, Expression query, IParameterValues parameterValues, | ||
bool parameterize = true, bool generateContextAccessors = false) | ||
{ | ||
return new OpenEdgeParameterExtractingExpressionVisitor(_evaluatableExpressionFilter, parameterValues, logger, | ||
_currentDbContext.Context, | ||
parameterize, generateContextAccessors).ExtractParameters(query); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/EFCore.OpenEdge/Query/Internal/OpenEdgeResultOperatorHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using JetBrains.Annotations; | ||
using Microsoft.EntityFrameworkCore.Metadata; | ||
using Microsoft.EntityFrameworkCore.Query; | ||
using Microsoft.EntityFrameworkCore.Query.Expressions; | ||
using Microsoft.EntityFrameworkCore.Query.ExpressionVisitors; | ||
using Microsoft.EntityFrameworkCore.Query.Internal; | ||
|
||
namespace EntityFrameworkCore.OpenEdge.Query.Internal | ||
{ | ||
public class OpenEdgeResultOperatorHandler : RelationalResultOperatorHandler | ||
{ | ||
public OpenEdgeResultOperatorHandler(IModel model, | ||
ISqlTranslatingExpressionVisitorFactory sqlTranslatingExpressionVisitorFactory, | ||
ISelectExpressionFactory selectExpressionFactory, | ||
IResultOperatorHandler resultOperatorHandler) | ||
: base(model, sqlTranslatingExpressionVisitorFactory, | ||
selectExpressionFactory, resultOperatorHandler) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters