I am trying to apply conditions on foreign key of customer entity i.e Orders, I want to load only the orders whose IsCancelFlag is false.(The result will be of type customer i.e Customer object, and it conatins a set of Order objects) But while iterating through the returned results, I can see all the orders under the customer, irrespective of whether its cancelled or not. Is it possible to apply conditions on foreign key in nhibernate
ICriteria _criteria= session.CreateCriteria<Customer>();
_criteria.Add(Expression.Eq("CustomerId", 12));
_criteria.CreateAlias("FKorders","FKorders");
_criteria.Add(Expression.Eq("FKorders.IsCancelFlag", false));
return _criteria.UniqueResult<Customer>();
your Property names seems weired but maybe you want
this will return a
ILookup<Customer, Orders>. NHibernate won’t return a Customer with partially initialised Orders since this will be a broken model and change tracking would be broken.