开发者

Strange LINQ to SQL Behavior

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):

开发者_JAVA技巧    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?


"%<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>


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜