【发布时间】:2017-01-31 21:15:22
【问题描述】:
我基本上是在尝试按月和年分组的日期“档案”。但是我的问题是数据库中的日期是字符串...不是我的选择。
这是我获取日期组列表的代码
var dates = dbBlog.Data
.GroupBy(o => new
{
Month = Convert.ToDateTime(o.date).Month,
Year = Convert.ToDateTime(o.date).Year
})
.Select(g => new BlogArchiveClass
{
Month = g.Key.Month,
Year = g.Key.Year,
Total = g.Count()
})
.OrderByDescending(a => a.Year)
.ThenByDescending(a => a.Month)
.ToList();
但是当我使用它时,我得到了这个错误:
LINQ to Entities does not recognize the method 'System.DateTime ToDateTime(System.String)
如何使用数据库中的字符串日期完成我正在做的事情?
【问题讨论】:
-
尽你所能来正确地设计数据库。不要满足于“不可能”。日期作为字符串将是一个持续的颈部疼痛。
标签: c# asp.net entity-framework linq