我有一个相当复杂的查询,我在其中使用 LIKE 语句过滤结果。这是查询:
var qsFilter = entities.QueryStatements.Where("it.Statement LIKE @searchTerm",
new ObjectParameter("searchTerm", searchTerm));
var qtFilter = entities.QueryTables.Where("it.TableNames LIKE @searchTables",
new ObjectParameter("searchTables", searchTerm));
接着:
var tables = from t in entities.TraceLines
join qs in qsFilter on t.QueryStatementHash equals qs.QueryStatementHash
join qt in qtFilter on qs.QueryTableHash equals qt.QueryTableHash
where t.CallTypeId == 64
orderby t.Sequence
select new
{
Name = qt.TableNames
};
问题在于,在最终查询中,它为 2 个 LIKE 过滤器生成了一个 AND 子句:
WHERE ([Filter1].[Statement] LIKE @searchTerm) AND
([Extent3].[TableNames] LIKE @searchTables)
我如何让它成为一个OR子句?
注意:如果您想知道我为什么在这里使用 ESQL,那是因为:How to use SQL 'LIKE' with LINQ to Entities?