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: Materialize outer entity in groupjoin to examine changes in ou… #6387

Merged
merged 1 commit into from
Aug 27, 2016
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 @@ -272,8 +272,6 @@ private static IEnumerable<TResult> _GroupJoin<TOuter, TInner, TKey, TResult>(
var outerGroupJoinIncludeContext = outerGroupJoinInclude?.Initialize(queryContext);
var innerGroupJoinIncludeContext = innerGroupJoinInclude?.Initialize(queryContext);

var hasOuters = (innerShaper as EntityShaper)?.ValueBufferOffset > 0;

try
{
using (var sourceEnumerator = source.GetEnumerator())
Expand Down Expand Up @@ -319,18 +317,15 @@ var outer
break;
}

if (hasOuters)
{
nextOuter = outerShaper.Shape(queryContext, sourceEnumerator.Current);

if (!Equals(outer, nextOuter))
{
break;
}
nextOuter = outerShaper.Shape(queryContext, sourceEnumerator.Current);

nextOuter = default(TOuter);
if (!Equals(outer, nextOuter))
{
break;
}

nextOuter = default(TOuter);

inner = innerShaper.Shape(queryContext, sourceEnumerator.Current);

if (inner == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4650,6 +4650,48 @@ orderby c.City
select o);
}

[ConditionalFact]
public virtual void GroupJoin_with_different_outer_elements_with_same_key()
{
AssertQuery<Order, Customer>((os, cs) =>
os.GroupJoin(cs,
o => o.CustomerID,
c => c.CustomerID,
(o, cg) => new
{
o.OrderID,
Name = cg.Select(c => c.ContactName).FirstOrDefault()
}));
}

[ConditionalFact]
public virtual void GroupJoin_with_different_outer_elements_with_same_key_with_predicate()
{
AssertQuery<Order, Customer>((os, cs) =>
os.Where(o => o.OrderID > 11500).GroupJoin(cs,
o => o.CustomerID,
c => c.CustomerID,
(o, cg) => new
{
o.OrderID,
Name = cg.Select(c => c.ContactName).FirstOrDefault()
}));
}

[ConditionalFact]
public virtual void GroupJoin_with_different_outer_elements_with_same_key_projected_from_another_entity()
{
AssertQuery<OrderDetail, Customer>((ods, cs) =>
ods.Select(od => od.Order).GroupJoin(cs,
o => o.CustomerID,
c => c.CustomerID,
(o, cg) => new
{
o.OrderID,
Name = cg.Select(c => c.ContactName).FirstOrDefault()
}));
}

[ConditionalFact]
public virtual void SelectMany_Joined()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,15 @@ public virtual void FindQuerySourcesRequiringMaterialization(
.Create(queryModelVisitor)
.FindQuerySourcesRequiringMaterialization(queryModel);

foreach (var groupJoinClause in queryModel.BodyClauses.OfType<GroupJoinClause>())
var groupJoinClauses = queryModel.BodyClauses.OfType<GroupJoinClause>().ToList();
if (groupJoinClauses.Any())
{
_querySourcesRequiringMaterialization.Add(groupJoinClause.JoinClause);
_querySourcesRequiringMaterialization.Add(queryModel.MainFromClause);
foreach (var groupJoinClause in groupJoinClauses)
{
_querySourcesRequiringMaterialization.Add(groupJoinClause.JoinClause);
}

}
}

Expand Down
Loading