Skip to content

Commit

Permalink
Fix navigation in UserDefinedFunction (#30776)
Browse files Browse the repository at this point in the history
* Fix navigation

* add Visits_extention_childrens test
  • Loading branch information
beliakov-mb authored Jun 14, 2023
1 parent 3994ea9 commit f414770
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ protected override Expression VisitExtension(Expression extensionExpression)
}
else
{
navigationExpansionExpression = CreateNavigationExpansionExpression(entityQueryRootExpression, entityType);
navigationExpansionExpression = CreateNavigationExpansionExpression(
base.VisitExtension(entityQueryRootExpression), entityType);
}

return ApplyQueryFilter(entityType, navigationExpansionExpression);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.EntityFrameworkCore.Infrastructure.Internal;
using Microsoft.EntityFrameworkCore.Metadata.Internal;

namespace Microsoft.EntityFrameworkCore.Query.Internal;

public class NavigationExpandingExpressionVisitorTests
{
private class TestInterceptors : IInterceptors
{
public TInterceptor Aggregate<TInterceptor>()
where TInterceptor : class, IInterceptor
{
return null;
}
}

private class TestNavigationExpandingExpressionVisitor : NavigationExpandingExpressionVisitor
{
public TestNavigationExpandingExpressionVisitor()
: base(
null,
new QueryCompilationContext(new QueryCompilationContextDependencies(
null,
null,
null,
null,
null,
new ExecutionStrategyTest.TestExecutionStrategy(new MyDemoContext()),
new CurrentDbContext(new MyDemoContext()),
null,
null,
new TestInterceptors()
), false),
null,
null)
{
}

public Expression TestVisitExtension(Expression extensionExpression)
{
return base.VisitExtension(extensionExpression);
}
}

private class MyDemoContext : DbContext
{
protected internal override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseInMemoryDatabase(databaseName: "test");
}
}

private class TestEntityQueryRootExpression : EntityQueryRootExpression
{
public int VisitCounter = 0;

public TestEntityQueryRootExpression(IAsyncQueryProvider asyncQueryProvider, IEntityType entityType)
: base(asyncQueryProvider, entityType)
{
}

public TestEntityQueryRootExpression(IEntityType entityType)
: base(entityType)
{
}

protected override Expression VisitChildren(ExpressionVisitor visitor)
{
VisitCounter++;
return this;
}

}

private class A
{
public int B { get; set; }
}

[ConditionalFact]
public void Visits_extention_childrens()
{
var model = new Model();
var e = model.AddEntityType(typeof(A), false, ConfigurationSource.Explicit);
var visitor = new TestNavigationExpandingExpressionVisitor();
var testExpression = new TestEntityQueryRootExpression(e);

visitor.TestVisitExtension(testExpression);

Assert.Equal(1, testExpression.VisitCounter);
}
}

0 comments on commit f414770

Please sign in to comment.