当我已经从 linq 带回一个日期并转换为短日期字符串时,我正在尝试使用 linq 按日期排序:
var NOVs = from n in db.CT_NOVs
join i in db.CT_Inspectors on n.ARBInspectorID equals i.CTInspectorID
join v in db.CT_ViolationTypes on n.ViolationTypeID equals v.ViolationTypeID
join t in db.CT_Tanks on n.CargoTankID equals t.CargoTankID
join c in db.CT_Companies on t.CompanyID equals c.CompanyID
select new
{
n.NOVID,
n.NOVNumber,
NOVDate = n.NOVDate.Value.ToShortDateString(),
ARBInspectorFirstName = i.FirstName,
ARBInspectorLastName = i.LastName,
v.ViolationName,
t.CargoTankID,
c.CompanyName
};
这是我尝试按日期排序的地方,但由于我将日期时间转换为短日期字符串,因此出现错误:
if (column == "NOVDate")
{
if (sortDirection == "ascending")
NOVs = NOVs.OrderBy(b => Convert.ToDateTime(b.NOVDate));
else
NOVs = NOVs.OrderByDescending(b => Convert.ToDateTime(b.NOVDate));
}
关于如何按 NOVDate 排序的任何线索?