Criteria and/or operator


I make the Criteria add runtime on the server-side.
When I have a filter like (sql) : firstname = 'Jan' and lastname='Van'
In the document I see that we can set this in code like:

oCriteria.Add(Linq.Eq('firstname', 'Jan') and Linq.Eq('lastname', 'Van') );

But I must use this kind of code because the filter I get is a list.

oCriteria.Add(Linq.Eq('firstname', 'Jan');
oCriteria.Add(Linq.Eq('lastname', 'Van');

I think that this is a and-operator between the to add's.
But how can I set an or-operator between the two add's?


You can do something like this (pseudo-code):

  Expr: TLinqExpression;

  Expr := Cond[0] or Cond[1];
  for C := 2 to Count - 1 do
    Expr := Expr or Cond[C];

Wagner R. Landgraf2017-05-10 23:40:30

Ok, but how can I know If there is something in Expr?

Assigned(Expr)  --> error
(Expr<>Nil)  --> error

You can't. But depending on your logic, you don't need to know that. The example code I put above doesn't need to know that.