Search code examples
nhibernatenhibernate-criteria

Or statements in criterion


I have a list of orders, which are connected to a user-table. Each order can contain multiple users.

I then have a search area where an admin can search through all orders by searching for e.g. a last name.

If there is done a search for e.g. Smith, all orders where a user named smith should be shown, but how is this done with NHibernate and Criterion?

I first tried (users is a list of users):

crit.CreateCriteria("Users").Add(Restrictions.Like("LastName", Users))

but with no success.


Solution

  • use Query Over

    IList<Order> Order = Session.QueryOver<Order>().JoinQueryOver<User>(ord=>ord.user).Where(usr=>usr.LastName.IsSensitiveLike  ("Smith",MatchMode.Starts)).List<Order>();