Last active
August 29, 2015 14:11
-
-
Save melvinlee/ffb6bef51bf19faf4ba3 to your computer and use it in GitHub Desktop.
Using Dapper Micro-ORM.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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