I have an entity and its mapping:
public class Test
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual string Description { get; set; }
}
public class TestMap : EntityMap<Test>
{
public TestMap()
{
Id(x => x.Id);
Map(x => x.Name);
Map(x => x.Description);
}
}
I'm trying to run a query on it (to grab it out of the database):
var keyword = "test" // this is coming in from the user
keyword = keyword.ToLower(); // convert it to all lower-case
var results = session.Linq<Test>
.Where(x => x.Name.ToLower().Contains(keyword));
results.Count(); // execute the query
However, whenever I run this query, I get the following exception:
Index was out of range. Must be non-negative and less than the size of the
collection. Parameter name: index
Am I right when I say that, currently, Linq to NHibernate does not support ToLower()
? And if so, is there an alternative that allows me to search for a string in the middle of another string that Linq to NHibernate is compatible with? For example, if the user searches for kap
, I need it to match Kapiolani
, Makapuu
, and Lapkap
.
There seems to be a lot of confusion around this subject.
Contains
and StartsWith
map to the LIKE
operator in SQL. They are not case insensitive themselves; it's the collation that makes them case insensitive, so that depends on how your column/schema were created.Update (2010-04-09): bug confirmed and patch submitted, see https://nhibernate.jira.com/browse/NH-2169
Update (2010-05-21): patch was applied on 2010-05-01 and works as expected now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With