I am using left join in linq query. I need to check the left table value is null or not in the ON clause.

   join x in employeee on u.id equals x.userId into ux 
   from ujoinx in ux.DefaultIfEmpty()
   join y in department on ujoinx.id equals y.employeeId into xy 
   from xjoiny in xy.DefaultIfEmpty()
   select new {
      EmployeeSal = ujoinx!=null?ujoinx.employeeSal:0, 
      EmployeeTax = ujoinx!=null?ujoinx.employeeTax:0, 
      UserName = u.username,
      DeptName = xjoiny!=null?xjoiny.name:""         
   }

Here I want to check ujoinx is not null in this join condition. join y in department on ujoinx.id equals y.employeeId into xy.

Is there any possibility to check the null condition with ujoinx.id equals y.employeeId?

1 Answers

0
TheIncorrigible1 On

In your comment, you placed the where clause in the wrong spot. You should filter before the join:

from ujoinx in ux.DefaultIfEmpty()
    where ujoinx != null
    join y in department on ujoinx.id equals y.employeeId
    into xy