【发布时间】:2021-06-26 03:52:19
【问题描述】:
我正在尝试根据下面的控制器获取最新日期,但遇到此错误:
“无法将类型为 'System.Data.Entity.Infrastructure.DbQuery1[<>f__AnonymousType201[System.Nullable`1[System.DateTime]]]' 的对象转换为类型 'System.IConvertible'。”
var latestDt = from n in db.Books
where n.id == id
select new { Date = n.dtBookBorrowed};
DateTime dtPlus1Year = Convert.ToDateTime(latestDt);
我可以知道如何在 linq 中仅获取列 latestDate 吗?
【问题讨论】:
-
类型在 C# 中至关重要。
latestDt的类型是什么?为什么你认为该类型不能转换为DateTime?
标签: asp.net-mvc linq datetime asp.net-mvc-4 max