Skip to content

Instantly share code, notes, and snippets.

View thiagoloureiro's full-sized avatar
🚗
Coding

Thiago thiagoloureiro

🚗
Coding
View GitHub Profile
public ConnectionFactory GetConnectionFactory()
{
var connectionFactory = new ConnectionFactory
{
HostName = "localhost",
UserName = "guest",
Password = "guest"
};
return connectionFactory;
}
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) =>
{
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
public class Address
{
public int Id { get; set; }
public string Street { get; set; }
public string City { get; set; }
public string Country { get; set; }
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }