Can this be done with Dapper?

Is it possible to do the following? I tried, but when he got to Query, he just said there is 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}); 

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 }); 

I was expecting select * from table WHERE a = @a OR ( b = @b )

but i got:

I was expecting select * from table WHERE a = @a AND ( b = @b )

+1
source share
1 answer

Presumably this is due to this error . An attempt to fix it was made on July 31, 2016, but there are still problems on this issue . It is planned that this will be fixed in the next major release.

0
source

All Articles