title: An exception of type 'System.NotSupportedException' while retrieving data in entityframe
body: <p>I have a class called ServiceDayWithEmployee that contains list of other class DaysWithSubCount
  here how the both classes look like...</p>
  
  <pre><code>public class ServiceDayWithEmployee
          {
              public int shiftID { get; set; }
              public string shiftName { get; set; }
              public int serviceDaysCount { get; set; }
              public List&lt;DaysWithSubCount&gt; days{ get; set; }
  
          }
  
          public class DaysWithSubCount
          {
                public int count { get; set; }
                public DateTime date { get; set; }
  
          }
  </code></pre>
  
  <p>I am tying to run a query to fill ServiceDayWithEmployee from database including the list of day.</p>
  
  <p>I am doing so in a foreach loop like the following...</p>
  
  <pre><code>foreach(shift sh in shifts)
              {
                  ServiceDayWithEmployee SDE= new ServiceDayWithEmployee();
                  SDE.shiftID=sh.id;
                  SDE.shiftName=sh.shift_name;
                  SDE.days = fleet.subscribtion_dates.Where(x =&gt; x.shift.Equals(sh.id)).GroupBy(x =&gt; x.date).Select(grp =&gt; new DaysWithSubCount { date = grp.Key.Value, count = grp.Count() }).ToList();
                  SDE.serviceDaysCount=SDE.days.Count;
                  SDEs.Add(SDE);
              }
  </code></pre>
  
  <p>This line of code gives me an exception and if I used var query instead of SDE.days and removed .ToList() it doesn't crash, but I don't know how to fill the days list then.</p>
  
  <pre><code> SDE.days = fleet.subscribtion_dates.Where(x =&gt; x.shift.Equals(sh.id)).GroupBy(x =&gt; x.date).Select(grp =&gt; new DaysWithSubCount { date = grp.Key.Value, count = grp.Count() }).ToList();
  </code></pre>
  
  <p>Here is the exception...</p>
  
  <pre><code>An exception of type 'System.NotSupportedException' occurred in System.Data.Entity.dll but was not handled in user code
  
  Additional information: Unable to create a constant value of type 'System.Object'. Only primitive types or enumeration types are supported in this context. 
  </code></pre>