与Dapper sqlbuilder结合使用

时间:2019-02-11 09:04:10

标签: sql-server dapper sqlbuilder

假设我想创建一个像这样的原始sql:

select a as code, b, c, d from tableA where b=@b and c=@c order by 1

这对于SQLBuilder很简单,我只是这样做(不能在代码上加上两个*):

dim builder as new Dapper.sqlbuilder

dim op = builder.addTemplate("select /*select*/ from tableA where /*where*/ /*orderby*/)"

builder.select("a as code, b, c, d")
builder.where("b=@b", new with {.b ="22"}
builder.where("c=@c", new with {.c ="33"}

builder.orderby("1")

dim sSQL as string = op.rawsql

但是,如果我希望使用UNION合并两个语句:

select a as code, b, c, d from tableA where b=@b and c=@c UNION select substring(e, 0, 4) as code, b, c, d from tableA where b=@b and c=@c order by 1

请问有没有办法使用sql builder?

非常感谢

0 个答案:

没有答案