How to use Dapper.QueryMultiple with Sqlite

.net c# dapper sqlite

Question

The Dapper documentation states you can send off multiple queries at once and iterate over the results using the QueryMultiple method like so:

var sql = @"
select * from foo where id = @paramname
select * from bar where id = @paramname";

conn.QueryMultiple(sql, new {paramname = paramval});

It would appear using sqlite like this doesn't work, throwing up invalid sql near "select". How do I use querymultiple with sqlite?

Accepted Answer

After some playing, I noted that you appear to need to use a semicolon between the commands

so the above code corrected becomes:

var sql = @"
select * from foo where id = @paramname;
select * from bar where id = @paramname";

conn.QueryMultiple(sql, new {paramname = paramval});

No, don't use the code like this, use the return of a QueryMultiple as a using statement, so it can be automatically disposed of.



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why