我正在我的应用程序中编写一个 linq 查询,我想在其上使用“小于”运算符。然而,我尝试将其应用到的列是字符串类型(我们无法更改),并且导致智能感知抛出错误,因为“<”运算符不能在字符串类型上使用。
我的问题是我还能怎么做?这是我的代码中发生错误的部分。
public ActionResult Index()
{
var results = Mapper.Map<IEnumerable<VesselViewModel>>(db.tbl_vessels
.Where(p =>
(p.vessel_type.Contains("AHTS")) &&
(p.spotlist_id == 2) &&
(p.fixture_start <= System.DateTime.Now.Date)
)
.ToList());
return View(results);
}
Run Code Online (Sandbox Code Playgroud)
fixture_start是一个字符串,由于其他地方的复杂性,我们无法更改它。无论如何,这个问题有解决办法吗?
如果p.fixture_start是包含日期的字符串,那么您必须在比较之前解析它:
(p => DateTime.Parse(p.fixture_start) <= System.DateTime.Now.Date)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21327 次 |
| 最近记录: |