title: How to pass a LINQ result to a method?
body: <p>From <a href="https://stackoverflow.com/questions/33699596/efficient-data-structure-to-hold-employees-activities">Efficient data structure to hold employee&#39;s activities?</a> , i have a List of type ActividadEmpleado which is declared as:</p>
  
  <pre><code>public string Empleado { get; set; }
  public DateTime Fecha { get; set; }
  public string Actividad { get; set; }
  </code></pre>
  
  <p>The LINQ query variable reorders the result in the way i need, which is to store by date and then by ActividadEmpleado and a string. However, var types cannot be passed to methods, so searching this site i am finding out that i either need to create a class to store the results or to modify the LINQ variable to return a List, but i am having issues with the proper declaration.</p>
  
  <p>The LINQ variable is:</p>
  
  <pre><code>var queryActividades = listaActividad
                  .GroupBy(a =&gt; a.Fecha, (fecha, fechaActividades) =&gt; new
                  {
                      Fecha = fecha,
                      FechaActividades = fechaActividades
                          .GroupBy(a =&gt; a.Empleado, (nombreEmpleado, actividadesEmpleado) =&gt; new
                          {
                              Actividades = actividadesEmpleado,
                              NombreEmpleado = nombreEmpleado
                          })
                          .OrderBy(a =&gt; a.NombreEmpleado)
                  })
                  .OrderBy(a =&gt; a.Fecha);
  </code></pre>
  
  <p>Visual Studio says that queryActividades is:</p>
  
  <pre><code>IOrderedEnumerable&lt;'a&gt;
  Anonymous Types:
  'a new datetime fecha, iorderedenumerable&lt;'b&gt;
  'b new IEnumerable&lt;ActividadEmpleado&gt; Actividades, string NombreEmpleado
  </code></pre>
  
  <p>I need to pass queryActividades to another method. I tried passing it as an Object but then i lose the extension methods such as Where&lt;> (can i cast it somehow?)</p>
  
  <p>I also read that declaring the results as a tuple should work, but i think declaring a new class is cleaner. </p>
  
  <p>I am just starting with LINQ, i have avoided it to use regular data structures but in this case it's really helpful and would like to know how to either handle anonymous types in them or convert the result to a regular List</p>
  
  <p>Final solution:</p>
  
  <pre><code>class GrupoActividad
  {
      public DateTime Fecha { get; set; }
      public IEnumerable&lt;Actividad&gt; Actividades { get; set; }
  }
  
  class Actividad
  {
      public IEnumerable&lt;ActividadEmpleado&gt; Actividades { get; set; }
      public string NombreEmpleado { get; set; }
  }
  
  var queryActividades = listaActividad
                  .GroupBy(a =&gt; a.Fecha, (fecha, fechaActividades) =&gt; new GrupoActividad
                  {
                      Fecha = fecha,
                      Actividades = fechaActividades
                          .GroupBy(a =&gt; a.Empleado, (nombreEmpleado, actividadesEmpleado) =&gt; new Actividad
                          {
                              Actividades = actividadesEmpleado,
                              NombreEmpleado = nombreEmpleado
                          })
                          .OrderBy(a =&gt; a.NombreEmpleado)
                  })
                  .OrderBy(a =&gt; a.Fecha);
  </code></pre>
  
  <p>Receiving method:</p>
  
  <pre><code>var actividades = from a in queryActividades
                         where a.Fecha == fechaCiclo
                         select new { a.Fecha, a.Actividades };
              foreach (var item in actividades)
              {
                  //cycle that holds each day's activities
                  foreach (var empleado in item.Actividades)
                  {
                      //cycle that holds each employee with activities in that day
                      foreach (var actividad in empleado.Actividades)
                      {
                          //final cycle that actually reads the activity
                          ActividadEmpleado actividadEmpleado = (ActividadEmpleado)actividad;
                      }
                  }
              }
  </code></pre>