开发者

Nested and/or expression in subsonic 2.2

开发者 https://www.devze.com 2023-03-17 03:06 出处:网络
I need to make a query like : SELECT * from TABLE WHERE cola= \"aaa\" and ( (colb = \"bbb\" and (colc=\"ccc\" or colc = \"ddd\"))

I need to make a query like :

SELECT * from TABLE
    WHERE cola= "aaa"
        and
        (
            (colb = "bbb" and (colc="ccc" or colc = "ddd"))
            or
            (colb="eee" and colc = "fff")
        )

I tried with Andexpression(), orexpression(), openexpression() or closeexpression(), but i can't figure it out ! Any help would 开发者_开发技巧be appreciated !


WhereExpression, AndExpression etc. should work (see also this question), but it doesn't work for me all the time, neither.

As long as your Where clauses are relatively simple, you could add some repetition and use logical operator precedence:

SELECT * from TABLE
    WHERE cola="aaa" AND colb="bbb" AND colc="ccc"
          OR
          cola="aaa" AND colb="bbb" AND colc="ddd"
          OR
          cola="aaa" AND colb="eee" AND colc="fff"

This would result in something like this:

DB.Select().From<TABLE>()
    .Where(TABLE.colaColumn).isEqualTo("aaa")
        .And(TABLE.colbColumn).isEqualTo("bbb")
        .And(TABLE.colcColumn).isEqualTo("ccc")
    .Or(TABLE.colaColumn).isEqualTo("aaa")
        .And(TABLE.colbColumn).isEqualTo("bbb")
        .And(TABLE.colcColumn).isEqualTo("ddd")
    .Or(TABLE.colaColumn).isEqualTo("aaa")
        .And(TABLE.colbColumn).isEqualTo("eee")
        .And(TABLE.colcColumn).isEqualTo("fff")
0

精彩评论

暂无评论...
验证码 换一张
取 消