Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello
i use linq contains query ,but it does not search insensitive??
what can i do for searching capital and small character???:confused:
Posted

Looks like you are using Contains in your LINQ where clause.

LINQ to SQL will translate a Contains() to a SQL LIKE statement which is not case sensitive in general.

Try:
OPTION 1:
s = From row In context.Table Where String.Compare(row.Name, "test", StringComparison.CurrentCulture) = 0

OR

OPTION 2:
If you want to use the Contains clause then, best way would be to create your own comparer. Look here:
Enumerable.Contains[^]
 
Share this answer
 
Comments
faezeh66 14-Jul-10 2:40am    
thanx for your attention
i cant use your solution because i should use it for many tables
Sandeep Mewara 14-Jul-10 2:43am    
I told what/how to do in case you want to use Contains.
Just Google for it if you find that difficult.
var Query = From row In context.Table Where System.Data.Linq.SqlClient.SqlMethods.Like(row.Name,"%test%")
 
Share this answer
 
Comments
faezeh66 14-Jul-10 2:34am    
thanx for your response
i want to use contains.... what should i do with contains?
Change the Collation in the database or write something like this:
tblUsers
.Where (u => u.userName.Contains("Test")).AsEnumerable()
.Where (u => u.userName.IndexOf("Test", StringComparison.CurrentCulture) != -1)
 
Share this answer
 
Just use ToLower() To compare both of them

C#
Thanks,
Hiren Solanki
{Mark as A Answer if it helps }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900