Generic repository with Dapper
<p>I'm trying to build a generic repository with Dapper. However, I have some difficulties to implement the CRUD-operations.</p>

<p>Here is some code from the repository:</p>

<pre><code> public class GenericRepository&lt;TEntity&gt; : IGenericRepository&lt;TEntity&gt; where TEntity : class
{
    internal IDbConnection Connection
    {
        get
        {
            return new SqlConnection(ConfigurationManager.ConnectionStrings["SoundyDB"].ConnectionString);
        }
    }

    public GenericRepository(string tableName)
    {
        _tableName = tableName;
    }

    public void Delete(TEntity entity)
    {
        using (IDbConnection cn = Connection)
        {

            cn.Open();
            cn.Execute("DELETE FROM " + _tableName + " WHERE Id=@ID", new { ID = entity.Id });
        }
    }
}
</code></pre>

<p>As you can see, my delete-method takes a TEntity as parameter which is a parameter of type class.</p>

<p>I call my Delete-method from my UserRepository like this:</p>

<pre><code>public class UserRepository : GenericRepository&lt;User&gt;, IUserRepository
{
    private readonly IConnectionFactory _connectionFactory;

    public UserRepository(IConnectionFactory connectionFactory) : base("User")
    {
        _connectionFactory = connectionFactory;
    }

    public async Task&lt;User&gt; Delete(User model)
    {
        var result = await Delete(model);
        return result;
    }
}
</code></pre>

<p>The thing is that I can't write <code>entity.Id</code> in my Delete-opration in my generic repository. I get a error. So how can I easily implement CRUD-operations like this?</p>

<p>Here is the error message:</p>

<blockquote>
  <p>TEntity does not contain a definition of "Id" and no extension method "Id" accepting a argument of type "TEntity" could be found</p>
</blockquote>