Saturday, May 12, 2012

Using Trim() in LINQ to SQL on an Empty string

This is kind of a silly thing I did, now that I think about it, but I must admit I was ignorant.

I didnt realize that you don't necessarily need a string utility to "Trim()" an Empty string of whitespaces, becuause, well, it doesn't matter.

To SQL, ' ' is same as '          '.

What I realized when using Trim() function, was this function was adding an overload of ltrim(rtrim(emptystringfield)) to my already resource intensive query, which in effect was increasing my query execution time. So use Trim() only when you need it, especially when using expensive queries.

No comments:

There was an error in this gadget