Skip to content

Commit

Permalink
Allow explicit loading of field-only navigations (#24548)
Browse files Browse the repository at this point in the history
Fixes #23717
  • Loading branch information
ajcvickers authored Apr 3, 2021
1 parent cff229a commit 3437c75
Show file tree
Hide file tree
Showing 31 changed files with 8,279 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/EFCore/Internal/ManyToManyLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Storage;

namespace Microsoft.EntityFrameworkCore.Internal
Expand Down Expand Up @@ -156,8 +157,8 @@ private IQueryable<TEntity> Query(
.AsTracking()
.Where(BuildWhereLambda(loadProperties, new ValueBuffer(keyValues)))
.SelectMany(BuildSelectManyLambda(_skipNavigation))
.NotQuiteInclude(BuildIncludeLambda(_skipNavigation.Inverse, loadProperties, new ValueBuffer(keyValues)))
.AsQueryable();
.NotQuiteInclude(BuildIncludeLambda(_skipNavigation.Inverse, loadProperties, new ValueBuffer(keyValues)))
.AsQueryable();
}

private static Expression<Func<TEntity, IEnumerable<TSourceEntity>>> BuildIncludeLambda(
Expand All @@ -173,8 +174,7 @@ private static Expression<Func<TEntity, IEnumerable<TSourceEntity>>> BuildInclud
EnumerableMethods.Where.MakeGenericMethod(typeof(TSourceEntity)),
Expression.MakeMemberAccess(
entityParameter,
// TODO-Nullable: This could be product bug.
skipNavigation.PropertyInfo!),
skipNavigation.GetIdentifyingMemberInfo()!),
Expression.Lambda<Func<TSourceEntity, bool>>(
ExpressionExtensions.BuildPredicate(keyProperties, keyValues, whereParameter),
whereParameter)), entityParameter);
Expand All @@ -197,8 +197,7 @@ private static Expression<Func<TSourceEntity, IEnumerable<TEntity>>> BuildSelect
return Expression.Lambda<Func<TSourceEntity, IEnumerable<TEntity>>>(
Expression.MakeMemberAccess(
entityParameter,
// TODO-Nullable: This could be product bug.
navigation.PropertyInfo!),
navigation.GetIdentifyingMemberInfo()!),
entityParameter);
}
}
Expand Down
21 changes: 21 additions & 0 deletions test/EFCore.InMemory.FunctionalTests/FieldsOnlyLoadInMemoryTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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 Microsoft.EntityFrameworkCore.TestUtilities;

namespace Microsoft.EntityFrameworkCore
{
public class FieldsOnlyLoadInMemoryTest : FieldsOnlyLoadTestBase<FieldsOnlyLoadInMemoryTest.FieldsOnlyLoadInMemoryFixture>
{
public FieldsOnlyLoadInMemoryTest(FieldsOnlyLoadInMemoryFixture fixture)
: base(fixture)
{
}

public class FieldsOnlyLoadInMemoryFixture : FieldsOnlyLoadFixtureBase
{
protected override ITestStoreFactory TestStoreFactory
=> InMemoryTestStoreFactory.Instance;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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 Microsoft.EntityFrameworkCore.TestUtilities;

namespace Microsoft.EntityFrameworkCore
{
public class ManyToManyFieldsLoadInMemoryTest : ManyToManyFieldsLoadTestBase<
ManyToManyFieldsLoadInMemoryTest.ManyToManyFieldsLoadInMemoryFixture>
{
public ManyToManyFieldsLoadInMemoryTest(ManyToManyFieldsLoadInMemoryFixture fixture)
: base(fixture)
{
}

public class ManyToManyFieldsLoadInMemoryFixture : ManyToManyFieldsLoadFixtureBase
{
protected override ITestStoreFactory TestStoreFactory
=> InMemoryTestStoreFactory.Instance;
}
}
}
Loading

0 comments on commit 3437c75

Please sign in to comment.