locked
How to join multiple 'tables' on multiple 'columns' RRS feed

  • Question

  • Can anyone tell me how to re-write this SQL query ias an EF query?

    select A.Column1,B.Column1,C.Column1
    FROM TableA as A INNER JOIN TableB as B ON
    A.ID1=B.ID1 and A.ID2=B.ID2
    INNER JOIN TableC as C ON
    B.ID1=C.ID1 and B.ID2=C.ID2
    WHERE A.ID1='1234'

    Thanks

    Wednesday, September 14, 2011 5:58 PM

Answers

  • I got it to work, using a sub-select I guess.

    var datasource = from a in dc.TableA join b in dc.TableB on new {a.ID1,a.ID2} equals new {b.ID1,b.ID2} into AB

    where a.ID1=='1234'

    select new {

       result = from ab in AB join c in dc.TableC on new {ab.ID1,ab.ID2} equals new {c.ID1,c.ID2}

       select new {a.Column1,b.Column1,c.Column1}

    }

    • Marked as answer by BradInDallas Wednesday, September 14, 2011 7:08 PM
    Wednesday, September 14, 2011 7:08 PM