Skip to content

Add left join support for Linq query provider #2328

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

Merged
merged 7 commits into from
May 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Comment Linq to Objects query
  • Loading branch information
maca88 committed Apr 21, 2020
commit fc8591aa896d71322bf2f4e951a80434f3410cd7
25 changes: 12 additions & 13 deletions src/NHibernate.Test/Async/Linq/LinqQuerySamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1285,24 +1285,24 @@ public async Task DLinqJoin9LeftJoinAsync(bool useCrossJoin)
Assert.Ignore("Dialect does not support cross join.");
}

ICollection expected, actual;
expected =
(from o in db.Orders.ToList()
from p in db.Products.ToList()
join d in db.OrderLines.ToList()
on new {o.OrderId, p.ProductId} equals new {d.Order.OrderId, d.Product.ProductId}
into details
from d in details.DefaultIfEmpty()
where d != null && d.UnitPrice > 50
select new {o.OrderId, p.ProductId, d.UnitPrice}).ToList();
// The expected collection can be obtained from the below Linq to Objects query.
//var expected =
// (from o in db.Orders.ToList()
// from p in db.Products.ToList()
// join d in db.OrderLines.ToList()
// on new { o.OrderId, p.ProductId } equals new { d.Order.OrderId, d.Product.ProductId }
// into details
// from d in details.DefaultIfEmpty()
// where d != null && d.UnitPrice > 50
// select new { o.OrderId, p.ProductId, d.UnitPrice }).ToList();

using (var substitute = SubstituteDialect())
using (var sqlSpy = new SqlLogSpy())
{
ClearQueryPlanCache();
substitute.Value.SupportsCrossJoin.Returns(useCrossJoin);

actual =
var actual =
await ((from o in db.Orders
from p in db.Products
join d in db.OrderLines
Expand All @@ -1313,11 +1313,10 @@ from d in details.DefaultIfEmpty()
select new {o.OrderId, p.ProductId, d.UnitPrice}).ToListAsync());

var sql = sqlSpy.GetWholeLog();
Assert.That(actual.Count, Is.EqualTo(163));
Assert.That(sql, Does.Contain(useCrossJoin ? "cross join" : "inner join"));
Assert.That(GetTotalOccurrences(sql, "left outer join"), Is.EqualTo(1));
}

Assert.AreEqual(expected.Count, actual.Count);
}

[Category("JOIN")]
Expand Down
25 changes: 12 additions & 13 deletions src/NHibernate.Test/Linq/LinqQuerySamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1829,24 +1829,24 @@ public void DLinqJoin9LeftJoin(bool useCrossJoin)
Assert.Ignore("Dialect does not support cross join.");
}

ICollection expected, actual;
expected =
(from o in db.Orders.ToList()
from p in db.Products.ToList()
join d in db.OrderLines.ToList()
on new {o.OrderId, p.ProductId} equals new {d.Order.OrderId, d.Product.ProductId}
into details
from d in details.DefaultIfEmpty()
where d != null && d.UnitPrice > 50
select new {o.OrderId, p.ProductId, d.UnitPrice}).ToList();
// The expected collection can be obtained from the below Linq to Objects query.
//var expected =
// (from o in db.Orders.ToList()
// from p in db.Products.ToList()
// join d in db.OrderLines.ToList()
// on new { o.OrderId, p.ProductId } equals new { d.Order.OrderId, d.Product.ProductId }
// into details
// from d in details.DefaultIfEmpty()
// where d != null && d.UnitPrice > 50
// select new { o.OrderId, p.ProductId, d.UnitPrice }).ToList();

using (var substitute = SubstituteDialect())
using (var sqlSpy = new SqlLogSpy())
{
ClearQueryPlanCache();
substitute.Value.SupportsCrossJoin.Returns(useCrossJoin);

actual =
var actual =
(from o in db.Orders
from p in db.Products
join d in db.OrderLines
Expand All @@ -1857,11 +1857,10 @@ from d in details.DefaultIfEmpty()
select new {o.OrderId, p.ProductId, d.UnitPrice}).ToList();

var sql = sqlSpy.GetWholeLog();
Assert.That(actual.Count, Is.EqualTo(163));
Assert.That(sql, Does.Contain(useCrossJoin ? "cross join" : "inner join"));
Assert.That(GetTotalOccurrences(sql, "left outer join"), Is.EqualTo(1));
}

Assert.AreEqual(expected.Count, actual.Count);
}

[Category("JOIN")]
Expand Down