我正在形成如下的字符串表达式。
string Condition = " it.person_id = " + personId.ToString();
if (lstPersonFields != null)
{
foreach (var field in lstPersonFields )
{
string fieldCondition = " And it." + field.FieldName.ToString();
if (field.FieldCondition == "Contains")
{
fieldCondition = fieldCondition + " Like '%" + field.FieldValue.ToString() + "%'";
}
else if (field.FieldCondition == "Equals")
{
fieldCondition = fieldCondition + " = '" + field.FieldValue.ToString()+"'";
}
Condition = Condition + fieldCondition;
}
}
var personSearch = FullPersonlst.Where(Condition).ToList();
上面的代码对于类似搜索中的日期时间值以外的其他值正常工作,并为日期时间字段抛出错误,如
Like arguments must be of string type
如何搜索日期时间字段?