是否可以使用Dapper构建此查询? [英] Is it possible to do this build this query with Dapper?

查看:76
本文介绍了是否可以使用Dapper构建此查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以执行以下操作?我试过了,但是到查询时,它只是说存在空引用。

Is it possible do do the following? I tried, but when it got to the Query, it just said there was a null reference.

   var builder = new StringBuilder("select * from my table1 where 1 = 1");

if(x==1)
    builder.Append(" and x = @x");

if(y==2)
    builder.Append(" and y = @y");

// when it gets here, it just says null reference

 db.Query<table1>(builder.ToString(), new {x,y});

我让SqlBuilder在.net 3.5中运行,但是当我这样做时:

I got SqlBuilder to run in .net 3.5, but when I do this:

var builder = new SqlBuilder();

var sql = builder.AddTemplate("select * from table /**where**/ /**orderby**/");

 builder.Where("a = @a", new { a = 1 })
        .OrWhere("b = @b", new { b = 2 });

我期望 select * from table WHERE a = @a OR(b = @b)

但是我得到了:

我期望从表WHERE中选择* a = @a AND(b = @b)

推荐答案

大概是由于此错误引起的。尝试修复的时间为2016年7月31日,但是使用此方法仍然存在问题。计划在下一个主要版本中对此进行修复。

Presumably this was due to this bug. The attempted fix was made on Jul 31 2016 however there are still issues with this approach. The plan is that this would be fixed in the next major release.

这篇关于是否可以使用Dapper构建此查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆