Skip to content

Instantly share code, notes, and snippets.

@melvinlee
Last active August 29, 2015 14:11
Show Gist options
  • Save melvinlee/ffb6bef51bf19faf4ba3 to your computer and use it in GitHub Desktop.
Save melvinlee/ffb6bef51bf19faf4ba3 to your computer and use it in GitHub Desktop.
Using Dapper Micro-ORM.
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Dapper;
public class Repository
{
private readonly Func<IDbConnection> _connection;
public Repository(Func<IDbConnection> connection)
{
_connection = connection;
}
public List<Caller> Get(string callerid)
{
var sqlBuilder = new StringBuilder();
var query = sqlBuilder.Append("SELECT id, `last_name` as name FROM contacts ")
.Append(" WHERE phone_work =@callerid")
.ToString();
try
{
using (var con = _connection())
{
return con.Query<Caller>(query, new { callerid }).ToList();
}
}
catch (Exception exception)
{
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment