我正在使用 Linq to DataTable。我如何在 where 子句中应用 like 运算符。我想像 SQL 中的 like 运算符一样对数据进行搜索。
我搜索并尝试了以下代码,但出现错误:Method 'Boolean Like(System.String, System.String)' cannot be used on the client;它仅用于转换为 SQL。
var details = from addresses in dt.AsEnumerable()
where SqlMethods.Like(prefixText, prefixText + "%") || SqlMethods.Like(prefixText, "%" + prefixText + "%")
select (string) addresses["Details"];
return details.ToArray();
最佳答案
您最好的选择可能是将其重写为正则表达式以供使用
where yourRegex.IsMatch(row.SomeValue)
或者如果它只是以查询开头:
where row.SomeValue.StartsWith(prefix)
关于c# - 像 Linq to DataTable 中的运算符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4463668/