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


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 in varchar ) i did it:
z: Variant;
z := VarArrayCreate([0, 1], varOleStr);
for i := 0 to 1 do begin
VarArrayPut(z, IntToStr(i + 10), i);

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

Here is my entity:
[ Inheritance( TInheritanceStrategy.JoinedTables ) ]
[ Entity, Automapping ]
[ Table( 'order' ) ]
[ Id( 'Fid', TIdGenerator.None ) ]
TOrder = class
[ 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 ))
gave error "Invalid variant type conversion "

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

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

Thank you, it works.

1 Like

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