Answered Linq Nubie, Nested Query

  • Thursday, January 31, 2013 3:35 AM
     
     

    Hi, I am trying to get a patients records from a detail table based on the entries in the patient table, detail table contains details for patients, doctors nurses. In sql I would write a simple nested select but need to do it in Linq! Any ideas how I could do this bearing in mind that I actually need no data from the patient table except for the detail number so I can use that to get the data out the detail table.

    Here is part of my erd to illustrate my design!

All Replies

  • Thursday, January 31, 2013 8:04 AM
     
     Answered

    I'm having a blog post about performing INNER JOIN operation with LINQ and I'm also discribing INNER JOIN operation using nested queries take a look, maybe it can help you

    http://msguy.net/post/2013/01/04/LINQ-Join-Operations.aspx#subquery-inner-join


    Please Mark as Reply and Vote as Helpful if I helped.

    Also please visit my blog http://msguy.net/

    • Marked As Answer by soulchyld Thursday, January 31, 2013 1:46 PM
    •  
  • Thursday, January 31, 2013 1:46 PM
     
      Has Code

    I can't see the illustration, but you can write it as two statements.

    var dict = from row in contect.InnerTable
               where whatever == 4
               select row.Id;
    
    var query = from row in context.OuterTable
                where dict.Contains(row.ForeignKey)
                select row;
    
    
    

  • Thursday, January 31, 2013 1:47 PM
     
     
    Thanks,