Page 1 of 1

select * from tab where field in ("val1", "val2");

Posted: Wed 23 Mar 2016 12:16
by elion
Hi,

how can I write the query in LINQ?

I can do something like

Code: Select all

    Query := Linq.From(FEntityContext['TAB'])
                 .Where(
                  (FEntityContext['TAB']['field'] = 'val1')
                  or
                  (FEntityContext['TAB']['field'] = 'val2'))
                 .Select();
But I need something like this (it dosn't work and has a run time error with wrong sytax!)

Code: Select all

    Query := Linq.From(FEntityContext['TAB'])
                 .Where('TAB.field in (''val1'',''val2'')')
                 .Select();
BUT the following code works! But it retruns no data!

Code: Select all

    Query := Linq.From(FEntityContext['TAB'])
                 .Where('TAB.field in ("val1'')')
                 .Select();
This code works and it returns data!

Code: Select all

    Query := Linq.From(FEntityContext['TAB'])
                 .Where('TAB.field = ''val1''')
                 .Select();
Could you help me?

Thx!

Re: select * from tab where field in ("val1", "val2");

Posted: Wed 23 Mar 2016 13:23
by AlexP
Hello,

LinqQuery in EntityDAC doesn't support the IN operator

Re: select * from tab where field in ("val1", "val2");

Posted: Wed 23 Mar 2016 13:32
by elion
AlexP wrote:Hello,

LinqQuery in EntityDAC doesn't support the IN operator
Okay, thx! Then I will use the code like

Code: Select all

    Query := Linq.From(FEntityContext['TAB'])
                 .Where(
                  (FEntityContext['TAB']['field'] = 'val1')
                  or
                  (FEntityContext['TAB']['field'] = 'val2'))
                 .Select();
or

Code: Select all

    Query := Linq.From('TAB')
                 .Where(
                  '(TAB.field = ''val1'') or (TAB.field = ''val2'')'
                  )
                 .Select();
Both works!

Alex, do you have maybe a better solution for my need? :-)

Re: select * from tab where field in ("val1", "val2");

Posted: Thu 24 Mar 2016 11:25
by AlexP
Yes, since the IN operator is not supported, you should use the OR operator.