I am trying to group by the date portion of a DateTime in Linq2db.MySQL.
My first attempt is:
using (var db = MySqlTools.CreateDataConnection(connectionString))
{
{
var query = from t in db.GetTable<Change_log>()
.Where(t => t.Action == 15)
.GroupBy(t => new { t.Change_date.Date, t.Reference_no }).Where(grp => grp.Count() > 1)
.SelectMany(t => t).ToList()
.OrderBy(t => t.Change_date)
select t;
But DateTime.Date isn’t recognized. I have tried installing MySQL.Data.Entity and Entity Framework and changing the GroupBy to
.GroupBy(t => new { dd = DbFunctions.TruncateTime(t.Change_date), t.Reference_no }).Where(grp => grp.Count() > 1)
but then I get the error:
‘TruncateTime (convert(selectParm.Change_date))’ Cannot be converted to SQL
Is this even possible in Linq2db?
Edit:
A proposed solution in another question was to create a function in the database which I have now done(fTruncateTime), returning Date(DateTime), but I don't know how to use it in my GroupBy clause.