0

I want to using join method for the following queryin Linq To SQL
What works correctly:

var db = new DatabaseDataContext();
db.DeferredLoadingEnabled = false;
var q = from p in db.Persons
        join c in db.Contacts on c.personId equal p.Id
        join j in db.Jobs on j.personId equal p.Id
        select SetPersonItems(p,c,j) ;

and what is SetPersonItems:

private Person SetPersonItems(Person p, Contact c, Job j)
{ 
   p.Contact = c;
   p.Job = j;
   return p;
}

What I need:
Now I would like using of Join Method for the above query. Like:

var q = db.Persons.Join<......>(db.Contacts,...).Join<....>(db.Jobs,...).Select....

p.s. Later I will create a dynamic method for the above Multiple Join (Join methods)

Hamid
  • 817
  • 1
  • 13
  • 29
  • 2
    So what's the actual question here? – Rahul Jul 11 '16 at 14:40
  • 1
    Possible duplicate of [How to perform Join between multiple tables in LINQ lambda](http://stackoverflow.com/questions/9720225/how-to-perform-join-between-multiple-tables-in-linq-lambda) – Adam Jul 11 '16 at 14:47
  • You want to implement eager loading? What is the point of your SetPersonItems function? – Pleun Jul 11 '16 at 15:33
  • @Rahul, Question is converting first query (which used join) to second type which using Join method. Actually I couldn't get correct result for second type (using Join method instead of using join) – Hamid Jul 11 '16 at 16:18
  • @Pleun, yes! and `SetPersonItems` will add `Job` and `Contact` properties to the `Person` rows and at end we have rows of Persons include their Contact and Job. – Hamid Jul 11 '16 at 16:21
  • @Hamid, go through MSDN documentation and you will get the answer. – Rahul Jul 11 '16 at 17:55
  • You should look into datacontext LoadWith options to force eager loading a – Pleun Jul 14 '16 at 19:50

0 Answers0