Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query: Expand owned FK navigation leading to non-owned entity #16967

Merged
merged 1 commit into from
Aug 5, 2019
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 @@ -67,12 +67,7 @@ protected override Expression VisitMember(MemberExpression memberExpression)
{
var innerExpression = Visit(memberExpression.Expression);
var expansion = TryExpandNavigation(innerExpression, MemberIdentity.Create(memberExpression.Member));
if (expansion != null)
{
return expansion;
}

return memberExpression.Update(innerExpression);
return expansion ?? memberExpression.Update(innerExpression);
}

protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression)
Expand Down Expand Up @@ -137,7 +132,7 @@ protected Expression ExpandNavigation(
return expansion;
}

if (navigation.ForeignKey.IsOwnership)
if (navigation.GetTargetType().IsOwned())
{
var ownedEntityReference = new EntityReference(navigation.GetTargetType());
ownedEntityReference.MarkAsOptional();
Expand Down
6 changes: 3 additions & 3 deletions test/EFCore.Specification.Tests/Query/OwnedQueryTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public virtual void Query_when_group_by()
}
}

[ConditionalFact(Skip = "Investigate")]
[ConditionalFact(Skip = "Issue#16330")]
public virtual void Query_when_subquery()
{
using (var context = CreateContext())
Expand Down Expand Up @@ -218,7 +218,7 @@ public virtual void Navigation_rewrite_on_owned_collection_with_composition()
}
}

[ConditionalFact(Skip = "Investigate")]
[ConditionalFact]
public virtual void Navigation_rewrite_on_owned_collection_with_composition_complex()
{
using (var ctx = CreateContext())
Expand Down Expand Up @@ -288,7 +288,7 @@ public virtual void Project_multiple_owned_navigations()
}
}

[ConditionalFact(Skip = "Investigate")]
[ConditionalFact]
public virtual void Project_multiple_owned_navigations_with_expansion_on_owned_collections()
{
using (var ctx = CreateContext())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,19 @@ public override void Navigation_rewrite_on_owned_collection_with_composition_com
base.Navigation_rewrite_on_owned_collection_with_composition_complex();

AssertSql(
@"");
@"SELECT (
SELECT TOP(1) [o].[PersonAddress_Country_Name]
FROM [Order] AS [o0]
LEFT JOIN (
SELECT [o1].[Id], [o1].[Discriminator]
FROM [OwnedPerson] AS [o1]
WHERE [o1].[Discriminator] IN (N'OwnedPerson', N'Branch', N'LeafB', N'LeafA')
) AS [t] ON [o0].[ClientId] = [t].[Id]
LEFT JOIN [OwnedPerson] AS [o2] ON [t].[Id] = [o2].[Id]
LEFT JOIN [OwnedPerson] AS [o] ON [o2].[Id] = [o].[Id]
WHERE [o3].[Id] = [o0].[ClientId])
FROM [OwnedPerson] AS [o3]
WHERE [o3].[Discriminator] IN (N'OwnedPerson', N'Branch', N'LeafB', N'LeafA')");
}

public override void SelectMany_on_owned_collection()
Expand Down Expand Up @@ -367,7 +379,24 @@ public override void Project_multiple_owned_navigations_with_expansion_on_owned_
base.Project_multiple_owned_navigations_with_expansion_on_owned_collections();

AssertSql(
@"");
@"SELECT (
SELECT COUNT(*)
FROM [Order] AS [o]
LEFT JOIN (
SELECT [o0].[Id], [o0].[Discriminator]
FROM [OwnedPerson] AS [o0]
WHERE [o0].[Discriminator] IN (N'OwnedPerson', N'Branch', N'LeafB', N'LeafA')
) AS [t] ON [o].[ClientId] = [t].[Id]
LEFT JOIN [OwnedPerson] AS [o1] ON [t].[Id] = [o1].[Id]
LEFT JOIN [OwnedPerson] AS [o2] ON [o1].[Id] = [o2].[Id]
LEFT JOIN [Planet] AS [p] ON [o2].[PersonAddress_Country_PlanetId] = [p].[Id]
LEFT JOIN [Star] AS [s] ON [p].[StarId] = [s].[Id]
WHERE ([o3].[Id] = [o].[ClientId]) AND (([s].[Id] <> 42) OR [s].[Id] IS NULL)) AS [Count], [p0].[Id], [p0].[StarId]
FROM [OwnedPerson] AS [o3]
LEFT JOIN [OwnedPerson] AS [o4] ON [o3].[Id] = [o4].[Id]
LEFT JOIN [OwnedPerson] AS [o5] ON [o4].[Id] = [o5].[Id]
LEFT JOIN [Planet] AS [p0] ON [o5].[PersonAddress_Country_PlanetId] = [p0].[Id]
WHERE [o3].[Discriminator] IN (N'OwnedPerson', N'Branch', N'LeafB', N'LeafA')");
}

public override void Navigation_rewrite_on_owned_reference_followed_by_regular_entity_filter()
Expand Down