我需要LIKE
在动态WHERE
子句中使用运算符。
我目前正在使用=
运算符,但需要替换为LIKE
:
String whereClause = "1 = 1 AND ";
whereClause = whereClause + (search.Id != null ? "Id = " + search.Id + " AND " : "");
whereClause = whereClause + (search.FirstName != null ? "FirstName = \"" + search.FirstName + "\" AND " : "");
whereClause = whereClause + (search.LastName != null ? "LastName = \"" + search.LastName + "\" AND " : "");
whereClause = whereClause + (search.StudentName != null ? "StudentName = \"" + search.StudentName + "\" AND " : "");
whereClause = whereClause + (search.Country != null ? "CountryLabel = \"" + search.Country + "\" AND " : "");
whereClause = whereClause + (search.ZipCode != null ? "ZipCode = \"" + search.ZipCode + "\" AND " : "");
whereClause = whereClause + (search.City != null ? "City = \"" + search.City + "\" AND " : "");
whereClause = whereClause.Remove(whereClause.Length - 5);
IEnumerable<MyClassDto> res = (
from ...
where ...
select new MyClassDto() {
...
}
).Where(whereClause);
- 我不能使用
Contains()
,StartsWith()
或者EndsWith()
搜索参数可以采用“%my%value”的形式。 - 我无法设法
SqlMethods.Like()
在动态WHERE
子句中使用。 - 我不想将它包含在查询的
WHERE
子句中,MyClassDto
因为它会减慢执行时间,这就是为什么我WHERE
在 上应用另一个子句Enumerable
,仅匹配搜索参数。
有什么建议么 ?