mirror of
https://github.com/zoriya/EntityFrameworkCore.Projectables.git
synced 2026-08-15 18:44:57 +00:00
Some additional tests and a bit of refactoring
This commit is contained in:
+1
-1
@@ -13,7 +13,7 @@ namespace EntityFrameworkCore.Projections.Infrastructure.Internal
|
||||
{
|
||||
readonly IQueryTranslationPreprocessorFactory _decoratedFactory;
|
||||
readonly QueryTranslationPreprocessorDependencies _queryTranslationPreprocessorDependencies;
|
||||
readonly ProjectableExpressionReplacer _projectableExpressionReplacer = new();
|
||||
readonly ProjectableExpressionReplacer _projectableExpressionReplacer = new(new ProjectionExpressionResolver());
|
||||
|
||||
public CustomQueryTranslationPreprocessorFactory(IQueryTranslationPreprocessorFactory decoratedFactory, QueryTranslationPreprocessorDependencies queryTranslationPreprocessorDependencies)
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace EntityFrameworkCore.Projections.Services
|
||||
{
|
||||
public class ExpressionArgumentReplacer : ExpressionVisitor
|
||||
public sealed class ExpressionArgumentReplacer : ExpressionVisitor
|
||||
{
|
||||
readonly IEnumerable<(ParameterExpression parameter, Expression argument)>? _parameterArgumentMapping;
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
|
||||
namespace EntityFrameworkCore.Projections.Services
|
||||
{
|
||||
public interface IProjectionExpressionResolver
|
||||
{
|
||||
LambdaExpression FindGeneratedExpression(MemberInfo projectableMemberInfo);
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EntityFrameworkCore.Projections.Services
|
||||
{
|
||||
public sealed class ParameterExtractor : ExpressionVisitor
|
||||
{
|
||||
List<ParameterExpression>? _extractedParameters = null;
|
||||
|
||||
protected override Expression VisitParameter(ParameterExpression node)
|
||||
{
|
||||
if (_extractedParameters is null)
|
||||
{
|
||||
_extractedParameters = new List<ParameterExpression>();
|
||||
}
|
||||
|
||||
_extractedParameters.Add(node);
|
||||
return base.VisitParameter(node);
|
||||
}
|
||||
|
||||
public IEnumerable<ParameterExpression> ExtractedParameters
|
||||
=> _extractedParameters ?? Enumerable.Empty<ParameterExpression>();
|
||||
}
|
||||
}
|
||||
@@ -7,13 +7,18 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace EntityFrameworkCore.Projections.Services
|
||||
{
|
||||
public class ProjectableExpressionReplacer : ExpressionVisitor
|
||||
public sealed class ProjectableExpressionReplacer : ExpressionVisitor
|
||||
{
|
||||
readonly ProjectionExpressionResolver _resolver = new();
|
||||
readonly IProjectionExpressionResolver _resolver;
|
||||
|
||||
public ProjectableExpressionReplacer(IProjectionExpressionResolver projectionExpressionResolver)
|
||||
{
|
||||
_resolver = projectionExpressionResolver;
|
||||
}
|
||||
|
||||
protected override Expression VisitMethodCall(MethodCallExpression node)
|
||||
{
|
||||
if (node.Method.GetCustomAttributes(true).OfType<ProjectableAttribute>().Any())
|
||||
if (node.Method.GetCustomAttributes(false).OfType<ProjectableAttribute>().Any())
|
||||
{
|
||||
var reflectedExpression = _resolver.FindGeneratedExpression(node.Method);
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ using EntityFrameworkCore.Projections.Extensions;
|
||||
|
||||
namespace EntityFrameworkCore.Projections.Services
|
||||
{
|
||||
public sealed class ProjectionExpressionResolver
|
||||
public sealed class ProjectionExpressionResolver : IProjectionExpressionResolver
|
||||
{
|
||||
readonly ConcurrentDictionary<string, LambdaExpression> _lookupCache = new();
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace EntityFrameworkCore.Projections.Services
|
||||
}
|
||||
|
||||
return expressionFactoryMethod.Invoke(null, null) as LambdaExpression ?? throw new InvalidOperationException("Expected lambda");
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user