在3.1中比较时间时,一直使用dateTime.compare()的写法,虽然linq里的封装内容一致
var queryWhere = ExtLinq.True<CheckPlanEntity>();
queryWhere = queryWhere.And(m => DateTime.Compare((DateTime)m.StartTime, DateTime.Now) <= 0);
queryWhere = queryWhere.And(m => DateTime.Compare((DateTime)m.EndTime, DateTime.Now) >= 0);
但到了3.2中比较两者时间时,在拉姆达表达式里使用datetime.compare会报出异常
拉姆达解析不支持当前函数Compare,SqlFunc这个类里面有大量函数可用,也许有你想要的,例如: it=>SqlFunc.HasValue(it.Id)\r\nEnglish Message : Expression parsing does not support the current function Compare. There are many functions available in the SqlFunc class, for example, it=>SqlFunc.HasValue(it.Id)"}
具体原因不详待调查,现在的做法是,时间范围,使用sqlFunc.Between
而两个时间比较的话就直接在表达式内比较大小,可以实现
1:时间范围
var start = Ext.GetDateTime(input.startTime.ToString());
var end = Ext.GetDateTime(input.endTime.ToString());
if (input.endTime != null && input.startTime != null)
{
start = new DateTime(start.Year, start.Month, start.Day, 0, 0, 0, 0);
end = new DateTime(end.Year, end.Month, end.Day, 23, 59, 59, 999);
whereLambda = whereLambda.And(x => SqlFunc.Between(x.CreatorTime, start, end));
}
//关键字(用户、IP地址、功能名称)
if (!string.IsNullOrEmpty(input.keyword))
{
whereLambda = whereLambda.And(m => m.UserName.Contains(input.keyword) || m.IPAddress.Contains(input.keyword) || m.ModuleName.Contains(input.keyword));
}
2:比较单个的时间
queryWhere = queryWhere.And(m => m.PlanExecTime <= DateTime.Now);