Calling ToLower() like you did would be the way to do it.  That being said,
I don't think the parser is handling method calls to ToLower.  A patch would
be welcome.

On Mon, Jul 6, 2009 at 1:09 PM, André Carlucci <[email protected]>wrote:

> Hi guys, first, thanks for this great framework.
>
> I have a similar problem concerning case-insensitive search.
>
> First, there is no such thing as "case-insensitive by default". I'm
> using Oracle and it does care about it. As nhibernate is database
> independent, it should care too.
>
> Also, the Equals() function beeing translated to "like" is also wrong,
> since Equals means... well... equals. The result of having this
> difference (== -> = and Equals -> like) will only make a lot of people
> create low performing queries, nothing more.
>
> I think the like operator should come in place when you call something
> like:
>
> var query = from p in session.Linq<User>()
>                 where p.Name.Contains(name)
>                 select p;
>
> And guest what: it works!
>
> The problem is when I want a case-insensitive query:
>
> var query = from p in session.Linq<User>()
>                 where p.Name.ToLower().Contains(name.ToLower())
>                 select p;
>
> The result is: System.ArgumentOutOfRangeException : Index was out of
> range. Must be non-negative and less than the size of the collection.
> Parameter name: index. Glup!
>
> So, when using a database that cares about case in like queries, how
> to perform a case-insensitive query?
>
> Thanks!
>
> André Carlucci
>
>
>
>
>
> On 2 abr, 01:33, Chad Lee <[email protected]> wrote:
> > Calling the .Equals method on a string generates a like query as you
> > discovered.  If you want to generate a SQL =, just do:
> > p.Email == userEmail
> >
> > As Fabio pointed out, I am not aware of any case-insensitive search in
> SQL
> > server.  It is all case-insensitive by default.
> >
> >
> >
> > On Tue, Mar 31, 2009 at 9:14 AM, Fabio Maulo <[email protected]>
> wrote:
> > > which is the SQL for caseInsensitive.
> >
> > > 2009/3/31 Robert Misiak <[email protected]>
> >
> > >> I am working on a project in which we're using session.Linq<T>() to do
> > >> a variety of searches using Lambda expressions.  We don't even have
> > >> nHibernate exposed to our application - we have a service layer with
> > >> methods that take Expression<Func<T, bool>> as a parameter which call
> > >> session.Linq<T>() with the passed parameter.
> >
> > >> We have a large table which was performing very slowly, and our DBA
> > >> found the nHibernate was doing a SQL LIKE behind the scenes instead of
> > >> using "=" which was a contributor to the slow performance.  The Lambda
> > >> expressions that were getting converted to a LIKE were like so:
> >
> > >> session.Linq<T>(p => p.Email.Equals(userEmail,
> > >> StringComparison.InvariantCultureIgnoreCase));
> >
> > >> This leads me to the following questions:
> >
> > >> 1. What is the preferred way to do a case-insensitive search using
> > >> nHibernate.Linq?
> > >> 2. Is this a bug or a feature?  Are there any plans to change this
> > >> behavior in the future?
> >
> > >> I think that it would be helpful if in future versions of
> > >> nHibernate.Linq, behavior related to case-(in)sensitivity or using SQL
> > >> LIKE was more transparent to the developer.
> >
> > >> FYI, in the mean-time, we've switched most of our simple queries to
> > >> use CreateCriteria().
> >
> > >> Regards,
> > >> Robert Misiak
> >
> > > --
> > > Fabio Maulo- Ocultar texto das mensagens anteriores -
> >
> > - Mostrar texto das mensagens anteriores -

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"NHibernate Contrib - Development Group" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com.ar/group/nhcdevs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to