nHibernate query by example with multiple associated objects

Posted by BurnWithLife on Stack Overflow See other posts from Stack Overflow or by BurnWithLife
Published on 2010-03-18T23:35:39Z Indexed on 2010/03/18 23:41 UTC
Read the original article Hit count: 252

Filed under:
|

I'm trying to use nhibernate's query by example to build dynamic queries. I'm stuck on how to code for an example object with multiple associations. Here's an example from NHibernate in Action. Its a User object with Items.

Example exampleUser =
Example.Create(u).IgnoreCase().EnableLike(MatchMode.Anywhere);
Example exampleItem =
Example.Create(i).IgnoreCase().EnableLike(MatchMode.Anywhere);
return GetSession().CreateCriteria(typeof(User))
.Add( exampleUser )
.CreateCriteria("Items")
.Add( exampleItem )
.List<User>();

If the User object has let's say a Category object as a property, how could I add that in to the above example? If i put another CreateCriteria at the end it refers to the Items, not the User.

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about criteria