In case we need to return the result of several different SELECT queries using one call to an SQL server.
It can be e.g. when we need to know the total items count and generate a pagination widget accordingly.
Doing it with one call is time efficient and performs better.
I recommend using Dapper's QueryMultiple extension method for this purpose
var sql = @"SELECT * FROM MyTable; SELECT COUNT(*) FROM MyTable";
var multi = connection.QueryMultiple(sql);
var myModel = multi.Read<MyModel>();
var count = multi.Read<int>()
It is very easy in comparison to the complicated workarounds with the Entity Framework.
Tags
database