Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ bool TryGetReflectedExpression(MemberInfo memberInfo, [NotNullWhen(true)] out La

protected override Expression VisitMethodCall(MethodCallExpression node)
{
// Replace MethodGroup arguments with their reflected expressions.
// Note that MethodCallExpression.Update returns the original Expression if argument values have not changed.
node = node.Update(node.Object, node.Arguments.Select(arg => arg switch {
UnaryExpression {
NodeType: ExpressionType.Convert,
Operand: MethodCallExpression {
NodeType: ExpressionType.Call,
Method: { Name: nameof(MethodInfo.CreateDelegate), DeclaringType.Name: nameof(MethodInfo) },
Object: ConstantExpression { Value: MethodInfo methodInfo }
}
} => TryGetReflectedExpression(methodInfo, out var expressionArg) ? expressionArg : arg,
_ => arg
}));

// Get the overriding methodInfo based on te type of the received of this expression
var methodInfo = node.Object?.Type.GetConcreteMethod(node.Method) ?? node.Method;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT [e].[Id], [e0].[Id] + 1, [e0].[Id]
FROM [Entity] AS [e]
LEFT JOIN [Entity] AS [e0] ON [e].[Id] = [e0].[EntityId]
ORDER BY [e].[Id]
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using EntityFrameworkCore.Projectables.FunctionalTests.Helpers;
using Microsoft.EntityFrameworkCore;
using VerifyXunit;
using Xunit;

namespace EntityFrameworkCore.Projectables.FunctionalTests;

[UsesVerify]
public class MethodGroupTests
{
public record Entity
{
public int Id { get; set; }

public List<Entity>? RelatedEntities { get; set; }
}

[Projectable]
public static int NextId(Entity entity) => entity.Id + 1;

[Fact]
public Task ProjectOverMethodGroup()
{
using var dbContext = new SampleDbContext<Entity>();

var query = dbContext.Set<Entity>()
.Select(x => new { NextIds = x.RelatedEntities!.Select(NextId) });

return Verifier.Verify(query.ToQueryString());
}
}