2

I don't know it its possible to have a nested or 2 or more on c.blah equals b.blah in one join statement in LINQ bacause i have to join a table without affecting the number of data

because if I add it to where theres a decrease of number of data and it acts as filter

What I tried as of the moment is adding && clause but it's not working

var Pos =  (from a in db.Position
            join b in db.Position_Location
             on a.ID equals b.PositionId
            join c in db.Customer
            on a.CustomerID equals c.ID
            join d in db.Customer_Location
            on b.LocationId equals d.ID 
            join f in db.Worker
             on userIdNew equals f.userId
            join e in db.Worker_Customer_Apply_Shift <----Planning to add new validation here
                     on a.ID equals e.Client_Customer_PositionID into trial
                 from newtrial in trial.DefaultIfEmpty()
                 where 
                       b.LogicalDelete == false
                       && a.LogicalDelete == false
                       && c.LogicalDelete == false
                       && d.LogicalDelete == false

                 select new
                 {
                     a.ID,
                     Client_CustomerID = c.ID,
                     LogicalDelete =(newtrial == null ? true : newtrial.LogicalDelete),


                 }).Distinct().ToList();

Thanks in Advance :)

Enrique Gil
  • 754
  • 4
  • 19
  • 50
  • possible duplicate of [How to do joins in LINQ on multiple fields in single join](http://stackoverflow.com/questions/373541/how-to-do-joins-in-linq-on-multiple-fields-in-single-join) – har07 Aug 06 '14 at 04:02

1 Answers1

2

You could use an anonymous type with the fields you want use in your join condition:

on new { a.One, a.Two } equals new { b.One, b.Two }

If the columns in both tables don't have the same names, you need to provide names for the properties of the anonymous type:

on new { Col1 = a.One, Col2 = a.Two } equals new { Col1 = b.Three, Col2 = b.Four }
Robby Cornelissen
  • 91,784
  • 22
  • 134
  • 156