I know this is an old question (like, 5 years old) but I was struggling with the same thing. The complete answer is in the comments to the other answer, but I thought I would offer a full example here.
string query = "SELECT * FROM MyTableName WHERE Foo = @Foo AND Bar = @Bar";
Dictionary<string, object> dictionary = new Dictionary<string, object>();
dictionary.Add("@Foo", "foo");
dictionary.Add("@Bar", "bar");
var results = connection.Query<MyTableName>(query, new DynamicParameters(dictionary));
Or, to be fully dynamic, you can create a method like this, which will take any model, any query, and any set of query parameters:
public static IEnumerable<T> Get<T>(string query, Dictionary<string, object> dictionary)
{
IEnumerable<T> entities = connection.Query<T>(query, new DynamicParameters(dictionary));
return entities;
}
And then to call this method:
var results = Get<MyTable>(query, dictionary)
EDIT LONG AFTER
This answer continues to get upvotes, so this is apparently still a need. I took this solution and created an entire data access NuGet package built on top of Dapper. It reduces your CRUD and query operations to a single line of code.
Here's the NuGet package.