wolli wrote:
Depending on your mapping it should be something like this:
var crit = Current.CreateCriteria(typeof (Case))
.Add(Restrictions.Eq("State", "Open"
.CreateCriteria("Customer", "c")
.Add(Restrictions.In("c.Name", listOfNames );
I should've described the problem a bit better.. Your solutions surely is correct, but the reason for wanting the "or" between was a bit more complicated. I wanted to do something like:
Code:
(State = "Open" AND Custmer.Name = "Pete")
OR (State = "Open" AND Custmer.Name = "Diane")
OR (State = "Closed" AND Customer.Age > 20)
OR ... etc., etc. ...
So an "In" restriction would not have satisfied. Thanks a bunch though..
I already formed a solution myself, once I accepted that a single alias could be used in more general sense than I first thought... Here is my solution (the code still is simplification for what I really need to do - but the real code is like 100 lines long, so I won't post it..besides I am not permitted to):
Code:
var crit = Current.CreateCriteria(typeof (Case));
var disj = new Disjunction();
disj.Add(Restrictions.Eq("State", "Open"));
crit.CreateAlias("Customer", "CustomerAlias");
disj.Add(Restrictions.Eq("CustomerAlias.Name", "Pete");
disj.Add(Restrictions.Eq("CustomerAlias.Name", "Diane");
crit.Add(disj);
var list = crit.List();
First, I thought I had to create many aliases for each new restriction, e.g. CustomerAlias1, CustomerAlias2 etc.
Thanks a bunch though..