如何更改最终表达式中2个ESQL where子句的条件?
我有一个相当复杂的查询,我使用 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,那是因为: 如何将 SQL 'LIKE' 与 LINQ to Entities 结合使用?
I have a fairly complex query where I am filtering results with a LIKE statement. Here is the query:
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));
And then:
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
};
The problem is that in the final query, it generates an AND clause for the 2 LIKE filters:
WHERE ([Filter1].[Statement] LIKE @searchTerm) AND
([Extent3].[TableNames] LIKE @searchTables)
How do I get that to be an OR clause?
Note: if you are wondering why I am using ESQL here, it is because of this: How to use SQL 'LIKE' with LINQ to Entities?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尽管我的 LinqToEntities 经验有限,但我对参考资料的阅读表明这可能有效:
我对那些不透明字符串中的“it”的用途感到困惑。码字的选择多么奇怪啊。
当然,如果你切换到 LinqToSql,你可以简单地这样写(但你已经知道了):
Although my LinqToEntities experience is limited, my reading of the reference materials suggests this might work:
I'm baffled at what the "it" is for in those opaque strings. What a strange choice of codeword.
Of course, if you switch to LinqToSql, you can simply write this (but you already knew that):