WorknHardr
asked on
LINQ Group By Key Format Date?
The group by Year/Month works fine, just cannot format the Key to a datetime. Keep getting this error:
" LINQ to Entities does not recognize the method 'System.String ToString(System.String)' method, and this method cannot be translated into a store expression. "
[Linq]
var model = (from b in context.Budgets
let j = new ViewModel { Budget = b }
let dt = j.Budget.Created
group j by new { y = dt.Year, m = dt.Month } into g
select new Group<string, ViewModel>
{
Key = Convert.ToDateTime(g.Key). ToString(" MM/yyyy"),
}
).ToList();
" LINQ to Entities does not recognize the method 'System.String ToString(System.String)' method, and this method cannot be translated into a store expression. "
[Linq]
var model = (from b in context.Budgets
let j = new ViewModel { Budget = b }
let dt = j.Budget.Created
group j by new { y = dt.Year, m = dt.Month } into g
select new Group<string, ViewModel>
{
Key = Convert.ToDateTime(g.Key).
}
).ToList();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Maybe in some future release.
Glad that worked out for you.
Glad that worked out for you.
ASKER
Thx
ASKER
I'm surprise Entity doesn't have a function like so:
EntityFunctions.TruncateDate(j.Budget.Created)