如何按linq中的列的部分字符串进行分组

时间:2017-07-25 13:38:03

标签: c# .net linq

我打算使用LINQ对日期列进行分组,因为日期列是DateTime格式,因此我无法按此列进行分组。最后,我需要按日期时间的部分值进行分组,以便根据日期生成报告。这就是我尝试过的。

var query = from data in entities.sales_order
            where data.status == "Completed" || data.status == "Shipped"
            group data by data.created_date.Value.ToString("ddMMyyyy") into g
            select new { dateKey = g.Key, dataList = g.ToList() };

但最终LINQ不接受查询中的ToString()(Substring)方法。

我可以知道如何解决这个问题吗?

如果我执行此操作,我将收到此错误enter image description here

如果我不包含ToString(" ddMMyyyy")代码正常运行

0 个答案:

没有答案