Generic Repository without Entity Framework Almost all of generic repository pattern tutorials were making use of EF, so I haven't got much sources to compare my code with. Here is what I have done. Could you please suggest me to fix my wrongs if I have or improve the code?

Note: I am using Dapper.Net as ORM, and I am aware of Dapper.Contrib dll, I just want to implement my own methods.

Generic Repository class

public interface IRepository&lt;T&gt; where T : BaseEntity
{
    IDbConnection Connection { get; set; }
    void Insert(T entity);
    void Delete(T entity);
    T GetById(int id);
    IQueryable&lt;T&gt; GetAll();
}


A Repository Class

public interface ICustomerRepository : IRepository&lt;Customer&gt;
{

}

public class CustomerRepository : ICustomerRepository
{
    public IDbConnection Connection { get; set; }

    public CustomerRepository()
    {
        Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["default"].ConnectionString);
    }

    public void Delete(Customer entity)
    {
        try
        {
            using (Connection)
            {
                Connection.Execute("DELETE FROM dbo.Customer Where Id = @Id", new { entity.Id });
            }
        }
        catch (Exception ex)
        {

        }
    }

    public IQueryable&lt;Customer&gt; GetAll()
    {
        IQueryable&lt;Customer&gt; list = new List&lt;Customer&gt;().AsQueryable();

        try
        {
            using (Connection)
            {
                list = Connection.Query&lt;Customer&gt;("SELECT * FROM dbo.Customer").AsQueryable();
            }
        }
        catch (Exception ex)
        {

        }
        return list;
    }

    public Customer GetById(int id)
    {
        Customer customer = new Customer();
        try
        {
            using (Connection)
            {
                customer = Connection.Query&lt;Customer&gt;("SELECT * FROM dbo.Customer WHERE Id = @Id", new { Id = id }).SingleOrDefault();
            }
        }
        catch (Exception ex)
        {

        }
        return customer;
    }

    public void Insert(Customer entity)
    {
        try
        {
            using (Connection)
            {
                Connection.Execute("INSERT INTO dbo.Customer VALUES(@FullName, @TcNo, @BirthDate)",
                    new
                    {
                        entity.FullName,
                        entity.Tcno,
                        entity.BirthDate
                    });
            }
        }
        catch (Exception ex)
        {

        }
    }
}


An Api Controller

public class CustomerController : ApiController
{
    private IRepository&lt;Customer&gt; _customerRepo;

    public CustomerController()
    {
        _customerRepo = new CustomerRepository(new SqlConnection(ConfigurationManager.ConnectionStrings["default"].ConnectionString));
    }
    [HttpGet]
    [Route("")]
    public IHttpActionResult Get()
    {
        return Json(_customerRepo.GetAll());
    }
}
I think you are in the right direction but let me suggest some things.

Remove the try catch and let the repository throw the exception. Either that or catch and throw your own exception.

Inject IDbConnection in the constructor of the repository and remove the using on the repository methods

    private IDbConnection _connection;

    public CustomerRepository(IDbConnection connection)
    {
        _connection = connection;
    }


Probably you want to use the repository in this way in many scenarios and with your current implementation you lose the transaction scope.

    public void DoWork()
    {
        using (var connection = ...)
        {
            //begin transaction
            var repository = new CustomerRepository(connection);
            var otherRepository = new OtherRepository(connection)
            var customer = repository.GetById(2);
            //do some stuff
            otherRepository.Update()...
            repository.Delete(customer);
            //commit transaction
        }
    }


This can be combined with IoC container.