My data class is
public class Data
{
public DateTime? Date { get; set; }
public int Count { get; set; }
}
And the following query
var queryable = db.MemberStats.Where(ms => ms.MemberId == User.Identity.GetUserId())
.GroupBy(n => TruncateTime(n.Commited))
.Select(g => new Data()
{
Date = g.Key,
Count = g.Count()
}
).ToList();
returns
System.NotSupportedException: 'Method 'System.Nullable`1[System.DateTime]
TruncateTime(System.Nullable`1[System.DateTime])' has no supported translation to SQL.'
What is wrong with that? How can i fix this one?
update: if i add ToList() before GroupBy() i have
at System.Data.Entity.Core.Objects.EntityFunctions.TruncateTime(Nullable`1 dateValue)
at .Controllers.ChartController.<>c.<Index>b__1_0(MemberStat n) in \Controllers\ChartController.cs:line 30
at System.Linq.Lookup`2.Create[TSource](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
at System.Linq.GroupedEnumerable`3.GetEnumerator()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.SystemCore_EnumerableDebugView`1.get_Items()