奇怪的 LINQ to SQL 行为

发布于 2024-09-04 21:40:56 字数 1338 浏览 2 评论 0原文

这是我的数据集:

1 David
2 David
3 Marc
4 Marc
5 Marc
6 Marc
7 Marc
8 Marc
9 Marc
10 Marc
11 Marc
12 Marc
13 Marc
14 Marc
15 Marc

此查询返回 2 条记录(正确):

    query = query.Where(Log => SqlMethods.Like
(Log.FormattedMessage, "%<key>Name</key><value>David</value>%"));

此查询返回 2 条记录(正确):

    query = query.Where(Log => SqlMethods.Like
(Log.FormattedMessage, "%<key>Name</key><value>%David%</value>%"));

此查询返回 0 条记录(正确):

    query = query.Where(Log => SqlMethods.Like
(Log.FormattedMessage, "%<key>Name</key><value>av</value>%"));

此查询返回 2 条记录(正确):

    query = query.Where(Log => SqlMethods.Like
(Log.FormattedMessage, "%<key>Name</key><value>%av%</value>%"));

此查询返回 0 条记录(正确):

    query = query.Where(Log => SqlMethods.Like
(Log.FormattedMessage, "%<key>Name</key><value>v</value>%"));

此查询返回 15 条记录(不正确,应返回 2 条):

    query = query.Where(Log => SqlMethods.Like
(Log.FormattedMessage, "%<key>Name</key><value>%v%</value>%"));

最后一个查询有什么问题?这是一个错误还是我错过了什么?

Here is my dataset:

1 David
2 David
3 Marc
4 Marc
5 Marc
6 Marc
7 Marc
8 Marc
9 Marc
10 Marc
11 Marc
12 Marc
13 Marc
14 Marc
15 Marc

This query returns 2 records (correct):

    query = query.Where(Log => SqlMethods.Like
(Log.FormattedMessage, "%<key>Name</key><value>David</value>%"));

This query returns 2 records (correct):

    query = query.Where(Log => SqlMethods.Like
(Log.FormattedMessage, "%<key>Name</key><value>%David%</value>%"));

This query returns 0 records (correct):

    query = query.Where(Log => SqlMethods.Like
(Log.FormattedMessage, "%<key>Name</key><value>av</value>%"));

This query returns 2 records (correct):

    query = query.Where(Log => SqlMethods.Like
(Log.FormattedMessage, "%<key>Name</key><value>%av%</value>%"));

This query returns 0 records (correct):

    query = query.Where(Log => SqlMethods.Like
(Log.FormattedMessage, "%<key>Name</key><value>v</value>%"));

This query returns 15 records (incorrect, should return 2):

    query = query.Where(Log => SqlMethods.Like
(Log.FormattedMessage, "%<key>Name</key><value>%v%</value>%"));

What is wrong with the last query? Is it a bug or am I missing something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

巴黎盛开的樱花 2024-09-11 21:40:56
"%<key>Name</key><value>%v%</value>%"

键/值之前/之后是什么?例如,我可以想象这个匹配:

<键>名称<值>斯坦< v值>凯尔

"%<key>Name</key><value>%v%</value>%"

What comes before/after key/value? For instance, I could imagine this matching it:

<key>Name</key><value> Stan</value>< v alue>Kyle </value>

隔岸观火 2024-09-11 21:40:56

我能看到的唯一原因是,你有 %v% 作为过滤器,这意味着在正则表达式 (.+)v(.+) 中,基本上是任何带有 av 的值。如果这不是解决方案,您可以发布查询结果吗?

Only reason I can see is, that you have %v% as filter, which means in regex (.+)v(.+), basically any value with a v somewhere in it. If this isn't the solution, can you post the results of the queries please?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文