Tag Archives: dapper dynamic c# query

In Dapper, how do I execute and use the results of a dynamic query?

Dapper is a framework that allows for SQL queries to be mapped into object models.  In most cases you will know the result of your query set and can map them accordingly but there are cases where you may not know what the return set includes

Here is an example of how you can make use of dynamics in C# to accomplish that.

var query = conn.Query<object>("select * from some_dynamic_resultset");
foreach(dynamic row in query)
    int id = row.Id;