Criteria and/or operator

Hello,

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?

Regards,
Christophe

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



var 
  Expr: TLinqExpression;


begin
  Expr := Cond[0] or Cond[1];
  for C := 2 to Count - 1 do
    Expr := Expr or Cond[C];
  oCriteria.Add(Expr);
end;


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.