NHibernate - QBE and EnableLike ()

I have a problem using QBE with NHibernate.

Here's some 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;
}

      

I expect this example and criteria to return all individuals whose name begins with the letter "e". BUT, for this I had to insert an escape character in the example property of the object. Like this:

person.FirstName = "e%";

      

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

What am I doing wrong?

Thank!

+2


source to share


1 answer


im not an expert but it looks like you need to put a matchmode in your enablelike () like:

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



matchmode can be: start, end, exact and any

hope this help

+2


source







All Articles