Linking Table RRS feed

  • Question

  • So say i have 3 tables, A, B and C. 

    A has a field title. So I run a query which searches for the title 'Dog'. I get the Id of this record and join with table B, which has a foreign key to the id and get values from B! I then want to join again on table C but with the Id that I didn't know at the start? Do I need to write a new query or can I do this with a another type of join

    var q = from a in ANIMALS
            join q from QUEEN
            on = 
            where a.title = "DOG"
            select new {,}

    so I basically need that to query table C, but it would be more efficient to do it in the same query?

    Table C has a foreign key which is the id!

    Tuesday, November 13, 2012 8:38 PM


  • If you need a "DOG" record's ID to query C  table than everything is ok, you can do following:

    var q = from a in ANIMALS
            join q from QUEEN on = 
            join x from TableC on =
            where a.title = "DOG"
            select new {,}

    But I'd suggest you to do all this staff in SQL and bring the result to LINQ.

    Please mark as reply if helped.
    Also visit my blog

    • Marked as answer by Alexander Sun Thursday, November 22, 2012 7:18 AM
    Wednesday, November 14, 2012 8:04 AM