none
grouping by data in another table RRS feed

  • Question

  • I have the following tables in a database:

    TABLE 1

    Key1, String1

    TABLE2

    Key1, String2 

     

    Key1 is a primary key in the first table and a foreign key in the second table.

     

    What I want to do is group these such that I know what values of String2 are associated with a particular token of String1 in TABLE1.

    I know how to group TABLE1 by String1 already, i.e.

     

    var result = from s in dbContext.TABLE1
                      group s by s.String1 into grouping
                      select grouping;
    
    


    What I cannot figure out is what I need to do to aggregate all the String2s together across all the Key1s that have the same String1.  It doesn't seem to be nested groups but I could be wrong.  Can someone give me a pointer?  

     

    Thanks!

     

     

    Thursday, February 2, 2012 8:35 AM

Answers

  • Hi DanJosef;

    If I understand the question correctly this should give you what you are looking for.

    var result = from t1 in dbContext.TABLE1
                 from t2 in t1.TABLE2
                 group t1 by new { t1.String1, t2.Sttring2 } into grouping
                 select grouping;
    

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Thursday, February 2, 2012 6:26 PM

All replies