The Inquisitive Coder - Davy Brion’s Blog

Thinking outside of the typical .NET box

IMultiQuery/IMultiCriteria usability improvement

Posted by Davy Brion on July 9th, 2008

A while ago i posted my query batcher which allowed you to use IMultiCriteria/IMultiQuery with key values instead of relying on the index position of the results.

I was asked to add those capabilities to NHibernate, so i submitted a patch for IMultiCriteria first, which was applied today. So i also submitted the patch for IMultiQuery.

So now you can basically do this:

            using (ISession session = OpenSession())

            {

                IMultiCriteria multiCriteria = session.CreateMultiCriteria();

 

                DetachedCriteria firstCriteria = DetachedCriteria.For(typeof(Item))

                    .Add(Expression.Lt(“id”, 50));

 

                DetachedCriteria secondCriteria = DetachedCriteria.For(typeof(Item));

 

                multiCriteria.Add(“firstCriteria”, firstCriteria);

                multiCriteria.Add(“secondCriteria”, secondCriteria);

 

                IList secondResult = (IList)multiCriteria.GetResult(“secondCriteria”);

                IList firstResult = (IList)multiCriteria.GetResult(“firstCriteria”);

 

                Assert.Greater(secondResult.Count, firstResult.Count);

            }

Same thing for IMultiQuery, but with hql queries instead of criteria obviously.

This has been added to the trunk, so i’m not sure if this will be ported to the NH2.0 branch, but at least it should be available for NH2.1 :)

update: the second patch has also been applied

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>