我想将字符串值转换为日期时间
类
public class demoDate
{
public DateTime DueDate;
public int OrderReportID;
public DateTime _DueDate
{
get { return DueDate; }
set { DueDate = value; }
}
public int _OrderReportID
{
get { return OrderReportID; }
set { OrderReportID = value;}
}
}
询问
var DateQuery = (from o in db.Order_Reports
select new demoDate {
DueDate = System.DateTime.Parse(o.ReportDueDateTime),
OrderReportID = o.OrderReportID
}).ToList();
此编码显示以下错误
LINQ to Entities无法识别方法'System.DateTime Parse(System.String)',并且该方法无法转换为商店表达式。
您需要首先将查询具体化(即加载数据)到您的应用程序,然后解析它。实体框架不知道如何执行.Net方法(例如DateTime.Parse
),仅知道如何将其转换为SQL
var DateQuery = db.Order_Reports.ToList().Select(o => new demoDate
{
DueDate=DateTime.Parse(o.ReportDueDateTime),
OrderReportID= o.OrderReportID
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句