GroupJoin vs. Where to filter out null elements

Is there any advantage to using either of these to retrieve items from Table A that don't have an associated item in TableB?

TableA
   .GroupJoin(
      TableB,
      o => o.TableAID,
      i => i.TableAID,
      (o,i) => new {o, child = i.DefaultIfEmpty()})
   .Where(x => x.child.Where(c => c != null).Count() == 0)
   .Select(x => x.o);

      

or

TableA
   .Where(a => !TableB.Select(b => b.TableAID).Contains(a.TableAID));

      

I'm used to doing this with the left outer join in SQL which is used in the first example. The second example uses a "NOT IN" approach that was not previously used for this.

Both methods return the same data. The second one will be my preferred one for simplicity. Do the former have advantages?

Do you have any other way to do this?

0


a source to share


1 answer


The SQL Server Query Optimizer will do the same with LEFT JOIN WHERE b is NULL

as WHERE IN

it does with ... Confirm this by reviewing the estimated execution plan.



0


a source







All Articles