Filtering the entity according to the list (possibly, _in function)

Hi

Is there any way to perform filtering of the entity?
Its like WHERE IN(), but dinamical.

Let say, I have TOrder entity and want to filter (I have already TArray with order numbers).
I tried at least add to Find method:
.Where(Linq['orderid'].Contains( myArray ))
.Where(Linq.contains('orderid', myArray ))
.Where(Linq['myArray ']._In( myArray))

Thank you in advance.

Forgot to mention "solution" so far, not the best but working:
.Where( Linq.sql( '{orderid} IN(''1'', "2")' ) )

_In method expects an array of Variant or TArray<Variant>. Just create your array with that type and you can pass it to it.

Exactly in that way (I have order.id in varchar ) i did it:
var
z: Variant;
begin
z := VarArrayCreate([0, 1], varOleStr);
for i := 0 to 1 do begin
VarArrayPut(z, IntToStr(i + 10), i);
end;

l = om.Find< TOrder >
.Where(Linq['id'].Contains( z ))
.List;

Here is my entity:
[ Inheritance( TInheritanceStrategy.JoinedTables ) ]
[ Entity, Automapping ]
[ Table( 'order' ) ]
[ Id( 'Fid', TIdGenerator.None ) ]
TOrder = class
private
[ Column( 'id', [ ], 18 ) ]
Fid: string;

But last command "l = om.Find<" gave error "Could not convert variant of type (Array OleStr) into type (OleStr)".

And second tryout (_in method)
l = om.Find< TOrder >
.Where(Linq['id']._In( z ))
.List;
gave error "Invalid variant type conversion "

It's not a Variant array. It's an array of Variant. This should work:

var
z: TArray<Variant>;
begin
  SetLength(z, 2);
  for i := 0 to 1 do begin
    z[i] := IntToStr(i + 10);
end;

Sure.
Thank you, it works.

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.