How to use Dapper with Linq
<p>I'm trying to convert from Entity Framework to Dapper to hopefully improve data access performance.</p>
<p>The queries I use are in the form of predicates like so <code>Expression&lt;Func&lt;TModel, bool&gt;&gt;</code>.</p>
<p>To give an example:</p>
<p>I have the following code which I need to convert to using Dapper.</p>
<p>What I currently do:</p>
<pre><code>public async Task&lt;List&lt;TModel&gt;&gt; Get(Expression&lt;Func&lt;TModel, bool&gt;&gt; query)
{
    // this.Context is of type DbContext
    return await this.Context.Set&lt;TModel&gt;().Where(query).ToListAsync();
}
</code></pre>
<p>What I'd like to do:</p>
<pre><code>public async Task&lt;List&lt;TModel&gt;&gt; Get(Expression&lt;Func&lt;TModel, bool&gt;&gt; query)
{
    using (IDbConnection cn = this.GetConnection)
    {
        return await cn.QueryAsync&lt;TModel&gt;(query);
    }
}
</code></pre>
<p>My google-fu is failing me, can someone please assist.</p>
<p>Edit:</p>
<p>Note that I did find:
<a href="https://github.com/ryanwatson/Dapper.Extensions.Linq" rel="nofollow noreferrer">https://github.com/ryanwatson/Dapper.Extensions.Linq</a></p>
<p>but I can't seem to figure out how to use it.</p>