奇怪的 LINQ to SQL 行为
这是我的数据集:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
键/值之前/之后是什么?例如,我可以想象这个匹配:
What comes before/after key/value? For instance, I could imagine this matching it:
我能看到的唯一原因是,你有
%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?