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

Add left join support for Linq query provider #2328

Merged
merged 7 commits into from
May 16, 2020

Conversation

maca88
Copy link
Contributor

@maca88 maca88 commented Mar 15, 2020

Fixes: #864

This PR provides two additional ways to do a left join:

  • Query syntax
from c in db.Customers
  join o in db.Orders on c.CustomerId equals o.Customer.CustomerId into orders
  from o in orders.DefaultIfEmpty()
  select o;
  • Extension method
db.Orders
  .LeftJoin(db.Orders, x => x.OrderId, x => x.OrderId - 1, (order, order1) => new { order, order1 })
  .Select(x => new { First = x.order, Second = x.order1 })
  .ToList();

@hazzik
Copy link
Member

hazzik commented Mar 21, 2020

Please resolve conflicts

@maca88
Copy link
Contributor Author

maca88 commented Mar 21, 2020

Rebased and commented the Linq to Objects query.

@maca88 maca88 changed the title WIP - Add left join support for Linq query provider Add left join support for Linq query provider Mar 21, 2020
@maca88
Copy link
Contributor Author

maca88 commented Mar 24, 2020

Rebased.

@fredericDelaporte fredericDelaporte added this to the 5.3 milestone Apr 22, 2020
@hazzik
Copy link
Member

hazzik commented Apr 24, 2020

@maca88 I'm trying to understand why we need booth NhJoin (which has a flag IsInner) and NhOuterJoin?

@hazzik hazzik self-requested a review April 24, 2020 10:31
@maca88
Copy link
Contributor Author

maca88 commented Apr 24, 2020

At first I tried to use NhJoin but it didn't worked out as it implements IFromClause, which requires fromExpression parameter that we don't have in this case. Ideally, if JoinClause would have a property whether it is an inner or outer join we wouldn't need NhOuterJoinClause, which would simplify the code and avoid registering both joins in QuerySourceIdentifier:

_namer.Add(outerJoinClause);
_namer.Add(outerJoinClause.JoinClause, _namer.GetName(outerJoinClause));

I was also thinking about tracking which JoinClause is an outer join in order to avoid having a wrapper, but the problem is that JoinClause can be cloned when rewriting the query model, which would probably ends up with a more complex solution.

@bahusoid
Copy link
Member

@hazzik Do you still have some pending questions/plans with reviewing this PR?

@hazzik hazzik merged commit d25d07b into nhibernate:master May 16, 2020
@bahusoid
Copy link
Member

Oups.. Something is not right... LINQ tests are failing on master after merge

@hazzik
Copy link
Member

hazzik commented May 16, 2020

There is some interference with #2324.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NH-2379 - Add support of Left Joins to Linq Provider
4 participants