user1110435
user1110435

Reputation: 31

Entity Framework 5.0 L2S Contains, StartsWith, EndsWith not working because of extra quotes

I have a simple request that filters the data, orders it and pages coming from an jQuery AutoComplete embedded in the toolbar of a Kendo Grid. Here is the code making the call.

Service.Get(s=> s.Name.Contains("Alcurt QI, In"), o => o.Name, 1, 15)

If I enter from the web the resulting SQL is correct however it embeds addition single quotes. The SQL is captured using SQL Profiler. Here is a snippet of the results:

WHERE [Extent1].[Name] LIKE @p__linq__0 ESCAPE N''~''
)  AS [Project1]
)  AS [Project1]
WHERE [Project1].[row_number] > 0
ORDER BY [Project1].[Name] ASC',N'@p__linq__0 nvarchar(4000)',@p__linq__0=N'%''Alcurt QI, In''%'

The Name column is nvarchar.

You see that it is using LIKE but, note the extra quotes

@p__linq__0=N'%''Alcurt QI, In''%'

If I remove the extra quotes the query works fine. I tested it out in SQL Manager.

I then wrote a Unit Test mocking the HttpContext and called the same controller action and the SQL works fine. Here is the SQL from it not the missing quotes.

WHERE [Extent1].[Name] LIKE @p__linq__0 ESCAPE ''~''
)  AS [Project1]
)  AS [Project1]
WHERE [Project1].[row_number] > 0
ORDER BY [Project1].[Name] ASC',N'@p__linq__0 varchar(8000)',@p__linq__0='%Alcurt QI, In%'

I have validated the EntityFramework version etc.

Why?

Upvotes: 0

Views: 604

Answers (1)

user1110435
user1110435

Reputation: 31

After reviewing the result I could not believe what I was seeing. So I stepped back and took a fresh look from the beginning abd there was a single quote right next to a quote. So the system was functioning as designed.

Upvotes: 1

Related Questions