Linq to Sql case insensitive equality

I read conflicting explanations about comparing Linq to Sql strings.

When I do the following:

  from p in db.People 
  where p.UserName=username
  select p

username = "JOHN"

I get the correct case insensitive. Does Linq do this by default or does it happen in a SQL database?

+5
source share
3 answers

I think that you get conflicting results depending on what your db variable points to and where the comparison is actually performed. If possible, linq will build the query and send it to the SQL server. It looks like you can make case insensitive cause

where p.UserName.ToLower()=username.ToLower()
+4
source

Your sample query will translate something like this:

[t0].col1, [t0].col2,..., [t0].coln []. [] [t0].UserName = @p0

... @p0 sql. , , .. , SQL Server/db/table/column. , DB DB, .

SQL Server (CI) , , , , , .

, , L2O (linq to objects), , , string.equals / ...

+3

It depends on the database. SQL Server 2008 treats rows as case-insensitive, including when used in an index expression. Linq does not.

Read on MSDN or this article .

+1
source