Skip to content

Instantly share code, notes, and snippets.

@thiagoloureiro
Created October 20, 2017 02:37
Show Gist options
  • Save thiagoloureiro/94f67c4acdc5edaf4c4a8ec1d9db6525 to your computer and use it in GitHub Desktop.
Save thiagoloureiro/94f67c4acdc5edaf4c4a8ec1d9db6525 to your computer and use it in GitHub Desktop.
List<Customer> ret;
using (var db = new SqlConnection(connstring))
{
var sql =
"select C.[Id], C.[Name], C.[Email], C.[Phone], A.CustomerId, A.Street, " +
"A.City, A.Country, A.ZIPCode from customer C " +
"inner join[Address] A on A.CustomerId = C.Id";
ret = db.Query<Customer, Address, Customer>(sql, (customer, address) =>
{
customer.Address = address;
return customer;
}, splitOn: "CustomerId").ToList();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment