Skip to content

Commit

Permalink
Query: Materialize outer entity in groupjoin to examine changes in ou…
Browse files Browse the repository at this point in the history
…ter element
  • Loading branch information
smitpatel committed Aug 26, 2016
1 parent 0823e25 commit 5953d96
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 31 deletions.
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

0 comments on commit 5953d96

Please sign in to comment.