c# - LINQ to Entities group-by failure using .date -


i trying linq group on date part of datetime field.

this linq statement works groups date , time.

var myquery = p in dbcontext.trends           group p p.updatedatetime g           select new { k = g.key, ud = g.max(p => p.amount) }; 

when run statement group date following error

var myquery = p in dbcontext.trends           group p p.updatedatetime.date g   //added .date on line           select new { k = g.key, ud = g.max(p => p.amount) }; 

the specified type member 'date' not supported in linq entities. initializers, entity members, , entity navigation properties supported.

how can group date , not date , time?

use entityfunctions.truncatetime method:

var myquery = p in dbcontext.trends           group p entityfunctions.truncatetime(p.updatedatetime) g           select new { k = g.key, ud = g.max(p => p.amount) }; 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

c# - How to execute a particular part of code asynchronously in a class -

c# - Asterisk click to call -