I have an already created NHibernate Criteria
query that I need to modified so I can add a new condition.
The query is based on the Order
object, which has a list of OrderItems
and then, every OrderItem
has a bool property named FinalDeliveryIndicator
.
In my Criteria query I need to add a condition in which I want all orders that at least one of its OrderItems
has the FinalDeliveryIndicator
bool set to true.
The query, at the moment, is:
var search = NHibernateSession.CreateCriteria(typeof(Order))
.CreateAlias("Contract", "C", JoinType.InnerJoin)
.CreateAlias("C.Supplier", "S", JoinType.InnerJoin)
.Add(Restrictions.Eq("Buyer.Id", companyId))
.Add(Restrictions.Eq("IsDeleted", false))
.Add(Restrictions.Eq("IsActiveVersion", true))
.SetFirstResult(paging.PageIndexSQL)
.SetMaxResults(paging.PageSize)
.AddOrder(SortOrder.Desc("Id"));
Now I need to add that condition I told you about. This query is already in use at many places on this application and so I cannot switch to QueryOver or some other type of query, due to the risk of crashing something.