Skip to content

Commit

Permalink
Add regression test for GroupBy scalar subquery
Browse files Browse the repository at this point in the history
Variation of #11133
  • Loading branch information
smitpatel committed Nov 22, 2019
1 parent 3e55597 commit 65a102e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5568,5 +5568,24 @@ public virtual Task Null_conditional_is_not_applied_explicitly_for_optional_navi
async,
ss => ss.Set<Level1>().Where(l1 => l1.OneToOne_Optional_FK1 != null && l1.OneToOne_Optional_FK1.Name == "L2 01"));
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task LeftJoin_with_Any_on_outer_source_and_projecting_collection_from_inner(bool async)
{
var validIds = new List<string> { "L1 01", "L1 02" };

return AssertQuery(
async,
ss => from l1 in ss.Set<Level1>().Where(l1 => validIds.Any(e => e == l1.Name))
join l2 in ss.Set<Level2>()
on l1.Id equals l2.Level1_Required_Id into l2s
from l2 in l2s.DefaultIfEmpty()
select new Level2
{
Id = l2 == null ? 0 : l2.Id,
OneToMany_Required2 = l2 == null ? null : l2.OneToMany_Required2
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2342,6 +2342,26 @@ public virtual Task Complex_query_with_groupBy_in_subquery4(bool async)
});
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task GroupBy_scalar_subquery(bool async)
{
return AssertQuery(
async,
ss => ss.Set<Order>()
.GroupBy(o => ss.Set<Customer>()
.Where(c => c.CustomerID == o.CustomerID)
.Select(c => c.ContactName)
.FirstOrDefault())
.Select(
g => new
{
g.Key,
Count = g.Count()
}),
elementSorter: e => e.Key);
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4312,6 +4312,22 @@ FROM [LevelOne] AS [l]
WHERE [l0].[Id] IS NOT NULL AND ([l0].[Name] = N'L2 01')");
}

public override async Task LeftJoin_with_Any_on_outer_source_and_projecting_collection_from_inner(bool async)
{
await base.LeftJoin_with_Any_on_outer_source_and_projecting_collection_from_inner(async);

AssertSql(
@"SELECT CASE
WHEN [l0].[Id] IS NULL THEN 0
ELSE [l0].[Id]
END, [l].[Id], [l1].[Id], [l1].[Level2_Optional_Id], [l1].[Level2_Required_Id], [l1].[Name], [l1].[OneToMany_Optional_Inverse3Id], [l1].[OneToMany_Optional_Self_Inverse3Id], [l1].[OneToMany_Required_Inverse3Id], [l1].[OneToMany_Required_Self_Inverse3Id], [l1].[OneToOne_Optional_PK_Inverse3Id], [l1].[OneToOne_Optional_Self3Id]
FROM [LevelOne] AS [l]
LEFT JOIN [LevelTwo] AS [l0] ON [l].[Id] = [l0].[Level1_Required_Id]
LEFT JOIN [LevelThree] AS [l1] ON [l0].[Id] = [l1].[OneToMany_Required_Inverse3Id]
WHERE [l].[Name] IN (N'L1 01', N'L1 02')
ORDER BY [l].[Id], [l1].[Id]");
}

private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1892,6 +1892,14 @@ FROM [Orders] AS [o]
GROUP BY [o].[CustomerID]");
}

[ConditionalTheory(Skip = "Issue#19027")]
public override async Task GroupBy_scalar_subquery(bool async)
{
await base.GroupBy_scalar_subquery(async);

AssertSql(" ");
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

Expand Down

0 comments on commit 65a102e

Please sign in to comment.