how to use entity framework to group by date not date with time

Use EntityFunctions.TruncateTime Method (Nullable<DateTime>). It will be transalated into TRUNCATETIME() TSQL function in generated SQL query, which does what you need:

Returns the expression, with the time values truncated.

So your code should be as follows:

//get data
var myData = from log in db.OperationLogs
             group log by EntityFunctions.TruncateTime(log.CreateTime) into g
             orderby g.Key
             select new { CreateTime = g.Key, Count = g.Count() };

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)