top X results in Dapper

For who does not know Dapper is a Micro-ORM

More specifically Dapper plays well to map SQL queries with strongly typed Classes and DapperParameters…

for the records, I am deeply in love with Dapper

const string SqlQuery = "select top (@top) * from Mytable "

using (var connection = OpenConnection())
{
return connection.Query<MyModel>(SqlQuery, new { top });
}

private IDbConnection OpenConnection()
{
var connection = new SqlConnection(_connectionString);
connection.Open();
return connection;
}
Advertisements