tags:

views:

262

answers:

1

Hi, I have a problem using QBE with NHibernate.

Here's a sample code:

Person person = new Person();
person.FirstName = "e";
using (ISession session = SessionFactory.CreateSession())
{
  Example example =    Example.Create(person).ExcludeProperty("DateOfBirth").EnableLike().IgnoreCase();
  IList<Person> people = session.CreateCriteria<Person>().Add(example).List<Person>();
  return people;
}

What I expect is that this example & criteria will return all persons whose first name starts with an "e". BUT, to accomplish this I had to insert escape character in the example object's property. Like this:

person.FirstName = "e%";

With this modification, query returns the desired results. Shouldn't the "EnableLike" take care of this?

What am I doing wrong?

Thanks!

A: 

im not an expert, but seems you need to put a matchmode in your enablelike(), just like:

Example.Create(person).ExcludeProperty("DateOfBirth") .EnableLike(NHibernate.Expression.MatchMode.Start) .IgnoreCase();

the matchmode can be:start, end,exact and anywhere

hope this help

Neodrabi