Skip to content

Instantly share code, notes, and snippets.

@tonyjoanes
Last active August 29, 2015 14:07
Show Gist options
  • Save tonyjoanes/3fe534e6f475b1690703 to your computer and use it in GitHub Desktop.
Save tonyjoanes/3fe534e6f475b1690703 to your computer and use it in GitHub Desktop.
Simple Dapper query and mapping
public class Person
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
public class PersonService
{
public Person GetPerson(int id)
{
var connectionString = ConfigurationManager.ConnectionStrings["DefaultDbConnection"].ConnectionString;
Person person = null;
using (var connection = new SqlConnection(connectionString))
{
connection.Open();
person = connection.Query<Person>("select * from person where id = @id", new { Id = 1 }).FirstOrDefault();
}
return person;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment