SQL produced by Entity Framework for string matching -


Looking at this linq query against an EF data reference:

  var customer = Data Customer (C => c.EmailDomain.StartsWith (term))  

You were expecting it to create a SQL like this, right?

  Select {Column} from customers where emailDomain @term + '%' like e-mails  

OK, in fact, it does something like this Is:

  SELECT {cols} FROM client where ((CAST (CHARINDEX (@term, EmailDomain)) = 1)  

Do you know is?

In addition, where the selector is:

  c => C.EmailDomain.Substring (0, term.Length) == word  

It runs 10 times faster but still produces some pretty yucky SQL.

Note: LINQ to SQL starts correctly like {{}}, and N. Hibernate has dedicated dedicated expressions. The reason for this is that CharIndex is very fast and cleaner compared to SQL performance. The reason for this is that you have some crazy "likes" sections in can . Example:

  select * from customer where 'ABC% DE% SSS%' like e-mail  

but, "Fourteenx" function (which Basically, "

Then, your answer is :)

EDIT: I just wanted to add that I used to use cheirandex in my SQL queries for those things I encourage those who do not need "likes" for them. It is important to note that in SQL Server 2000 ... A A "text" field can use the like method, but not CHARINDEX.


Comments