我正在尝试按 Linq2db.MySQL 中 DateTime 的日期部分进行分组。
我的第一次尝试是:
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;
但 DateTime.Date 无法识别。我尝试安装 MySQL.Data.Entity 和 Entity Framework 并将 GroupBy 更改为
.GroupBy(t => new { dd = DbFunctions.TruncateTime(t.Change_date), t.Reference_no }).Where(grp => grp.Count() > 1)
但后来我得到了错误:
'TruncateTime (convert(selectParm.Change_date))' 无法转换为 SQL
这在 Linq2db 中甚至可能吗?
编辑:
另一个问题中提出的解决方案是在我现在已经完成的数据库中创建一个函数(fTruncateTime),返回 Date(DateTime),但我不知道如何在我的 GroupBy 子句中使用它。