-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix to #5672 - Query :: Include with multiple navigations (including …
…optional navigation) fails Problem was that our include logic for groupjoin was expecting outer and inner elements (on which the include was being performed) to be entities. However sometimes those elements would be TransparentIdentifiers (e.g. when the element comes from a result of SelectMany). Fix is to also store (when necessary) the accessor from the outer/inner element to the entity that we want to include, extract the actual entity in runtime and apply include operations on that entity instead of the actual outer/inner element.
- Loading branch information
Showing
13 changed files
with
287 additions
and
7 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
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
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
78 changes: 78 additions & 0 deletions
78
src/Microsoft.EntityFrameworkCore.Specification.Tests/AsyncQueryNavigationsTestBase.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,78 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.EntityFrameworkCore.Specification.Tests.TestModels.Northwind; | ||
using Microsoft.EntityFrameworkCore.Specification.Tests.TestUtilities.Xunit; | ||
using Xunit; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Specification.Tests | ||
{ | ||
public abstract class AsyncQueryNavigationsTestBase<TFixture> : IClassFixture<TFixture> | ||
where TFixture : NorthwindQueryFixtureBase, new() | ||
{ | ||
[ConditionalFact] | ||
public virtual async Task Include_with_multiple_optional_navigations() | ||
{ | ||
await AssertQuery<OrderDetail>( | ||
ods => ods | ||
.Include(od => od.Order.Customer) | ||
.Where(od => od.Order.Customer.City == "London"), | ||
entryCount: 164); | ||
} | ||
|
||
[ConditionalFact] | ||
public virtual async Task Multiple_include_with_multiple_optional_navigations() | ||
{ | ||
await AssertQuery<OrderDetail>( | ||
ods => ods | ||
.Include(od => od.Order.Customer) | ||
.Include(od => od.Product) | ||
.Where(od => od.Order.Customer.City == "London"), | ||
entryCount: 221); | ||
} | ||
|
||
protected NorthwindContext CreateContext() | ||
{ | ||
return Fixture.CreateContext(); | ||
} | ||
|
||
protected AsyncQueryNavigationsTestBase(TFixture fixture) | ||
{ | ||
Fixture = fixture; | ||
} | ||
|
||
protected TFixture Fixture { get; } | ||
|
||
protected async Task AssertQuery<TItem>( | ||
Func<IQueryable<TItem>, IQueryable<object>> query, | ||
bool assertOrder = false, | ||
int entryCount = 0, | ||
Action<IList<object>, IList<object>> asserter = null) | ||
where TItem : class | ||
=> await AssertQuery(query, query, assertOrder, entryCount, asserter); | ||
|
||
protected async Task AssertQuery<TItem>( | ||
Func<IQueryable<TItem>, IQueryable<object>> efQuery, | ||
Func<IQueryable<TItem>, IQueryable<object>> l2oQuery, | ||
bool assertOrder = false, | ||
int entryCount = 0, | ||
Action<IList<object>, IList<object>> asserter = null) | ||
where TItem : class | ||
{ | ||
using (var context = CreateContext()) | ||
{ | ||
TestHelpers.AssertResults( | ||
l2oQuery(NorthwindData.Set<TItem>()).ToArray(), | ||
await efQuery(context.Set<TItem>()).ToArrayAsync(), | ||
assertOrder, | ||
asserter); | ||
|
||
Assert.Equal(entryCount, context.ChangeTracker.Entries().Count()); | ||
} | ||
} | ||
} | ||
} |
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
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
17 changes: 17 additions & 0 deletions
17
...soft.EntityFrameworkCore.SqlServer.FunctionalTests/AsyncQueryNavigationsSqlServerTests.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,17 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
using System.Threading.Tasks; | ||
using Microsoft.EntityFrameworkCore.Specification.Tests; | ||
using Xunit.Abstractions; | ||
|
||
namespace Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests | ||
{ | ||
public class AsyncQueryNavigationsSqlServerTests : AsyncQueryNavigationsTestBase<NorthwindQuerySqlServerFixture> | ||
{ | ||
public AsyncQueryNavigationsSqlServerTests(NorthwindQuerySqlServerFixture fixture, ITestOutputHelper testOutputHelper) | ||
: base(fixture) | ||
{ | ||
// TestSqlLoggerFactory.CaptureOutput(testOutputHelper); | ||
} | ||
} | ||
} |
Oops, something went wrong.