Q:

Get Sum of Property from Generic list having another generic list

I have below class
public class SearchResponse
{
       public string SearchTerm { get; set; }
       public List<DataClass> lstDataClass
       public string Category { get; set; }

}

public DataClass
{
        public String Date { get; set; }
        public string NoOfRecord { get; set; }
}

I will be having List<SearchResponse> and 
I want to have sum of NoOfRecord by grouping on Searchterm of SearchResponse class and Date of DataClass 
Suppose 
SearchResponse1
{
     SearchTerm="A";
    Category="cata";
     ListOfDataClass
    {
         dataclass
          {
             5 may 2013,
             50
          }
         dataclass
         {
              6 may 2013,
              68
         }
     }
}

SearchResponse2
{
     SearchTerm="A";
    Category="catb";
     ListOfDataClass
    {
         dataclass
          {
             5 may 2013,
             52
          }
         dataclass
         {
              6 may 2013,
              63
         }
     }
}

SearchResponse3
{
     SearchTerm="B";
    Category="catc";
     ListOfDataClass
    {
         dataclass
          {
             5 may 2013,
             48
          }
         dataclass
         {
              6 may 2013,
              21
         }
     }
}

I want
SearchTerm="A", Date=5 May 2013, TotalRecords=102
SearchTerm="A", Date=6 May 2013, TotalRecords=131
SearchTerm="B", Date=6 May 2013, TotalRecords=48
.
.
.

A:

A linq solution is this:
from x in
(
    from sr in SearchResponse
    from dc in sr.DataClass
    select new { sr.SearchTerm , dc }
)
group x by new { x.SearchTerm, x.dc.Date } into g
select new {
               g.Key.SearchTerm, 
               g.Key.Date, 
               TotalRecords = g.Sum(g1 => g1.p.NoOfRecord) 
           }

which first creates a flat list (new { sr.SearchTerm , dc }) in which Searchterm and Date can be grouped together. Subsequently, in each group the Sum is calculated.

