有可能做到以下几点吗?我试过了,但是当它进入Query时,它只是说有一个空引用。
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中运行,但是当我这样做时:
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 )
但我得到了:
我期望select * from table WHERE a = @a AND ( b = @b )