public void QueryBuilder_ShouldPopulateCustomerUsingParameter() { var customers = new SQLiteQueryBuilder <Customer>() .SetSql("select CustomerId, FirstName, LastName, Company, Address, City, State, Country, PostalCode, Phone, Fax, Email from Customer where CustomerId = $CustomerId") .AddParameter("$CustomerId", 19) .MapProperty(c => c.FullName, row => $"{row.GetString("FirstName")} {row.GetString("LastName")}") .GetResult().List; Assert.True(customers.First().FullName == "Tim Goyer"); }
public void QueryBuilder_ShouldPopulateZipFromPostalCode() { var customers = new SQLiteQueryBuilder <Customer>() .SetSql("select CustomerId, FirstName, LastName, Company, Address, City, State, Country, PostalCode, Phone, Fax, Email from Customer where CustomerId = $CustomerId") .AddParameter("$CustomerId", 19) .MapProperty(c => c.Zip, "PostalCode") .GetResult().List; Assert.True(customers.First().Zip == "95014"); }
public void QueryBuilder_ShouldBeAbleToSupplyConnection() { using (var conn = new SQLiteConnection(@"Data Source=Data\chinook.db;Version=3;")) { var customers = new SQLiteQueryBuilder <Customer>() .SetSql("select CustomerId, FirstName, LastName, Company, Address, City, State, Country, PostalCode, Phone, Fax, Email from Customer where CustomerId = $CustomerId") .AddParameter("$CustomerId", 19) .MapProperty(c => c.FullName, row => $"{row.GetString("FirstName")} {row.GetString("LastName")}") .GetResult(conn).List; Assert.True(customers.First().FullName == "Tim Goyer"); } }
public void QueryBuilder_ShouldPopulateInvoicesAndChildCustomer() { var invoices = new SQLiteQueryBuilder <Invoice>() .SetSql(@" select inv.*, cust.* from Invoice inv inner join Customer cust on inv.CustomerId = cust.CustomerId where cust.CustomerId = 19") .MapProperty(inv => inv.Customer, row => new Customer { CustomerId = row.GetInteger("CustomerId").Value, FirstName = row.GetString("FirstName"), LastName = row.GetString("LastName") }) .GetResult().List; Assert.True(invoices.First().Customer.FirstName == "Tim"); }