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

Discussion of open issues, suggestions and bugs regarding EntityDAC
Post Reply
elion
Posts: 29
Joined: Wed 10 Dec 2014 07:15

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

Post by elion » Wed 23 Mar 2016 12:16

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!

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

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

Post by AlexP » Wed 23 Mar 2016 13:23

Hello,

LinqQuery in EntityDAC doesn't support the IN operator

elion
Posts: 29
Joined: Wed 10 Dec 2014 07:15

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

Post by elion » Wed 23 Mar 2016 13:32

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? :-)

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

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

Post by AlexP » Thu 24 Mar 2016 11:25

Yes, since the IN operator is not supported, you should use the OR operator.

Post Reply