本文整理匯總了C#中Tailspin.SimpleSqlRepository.SqlStatement.InnerJoin方法的典型用法代碼示例。如果您正苦於以下問題:C# SqlStatement.InnerJoin方法的具體用法?C# SqlStatement.InnerJoin怎麽用?C# SqlStatement.InnerJoin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Tailspin.SimpleSqlRepository.SqlStatement
的用法示例。
在下文中一共展示了SqlStatement.InnerJoin方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetCustomer
public Customer GetCustomer(string userName)
{
var productRepo = new SimpleProductRepository();
Customer result = null;
var batch = new BatchSql();
//see if there's a customer - if not create one
object user = CustomersTable.Select(CustomersTable.Columns.UserName)
.Where(CustomersTable.Columns.UserName, userName)
.BuildCommand()
.ExecuteScalar();
if (user == null) {
CustomersTable.Insert(
new Dictionary<string, object>() {
{CustomersTable.Columns.UserName,userName},
{CustomersTable.Columns.LanguageCode,System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName}
})
.BuildCommand()
.ExecuteNonQuery();
}
//customer
batch.Append(CustomersTable.Select()
.Where(CustomersTable.Columns.UserName, userName));
//addresses
batch.Append(AddressesTable.Select()
.Where(AddressesTable.Columns.UserName, userName));
//shopping cart
Guid orderID = GetCartID(userName);
batch.Append(OrdersTable.Select()
.Where(OrdersTable.Columns.OrderID, orderID));
//items
//avert your eyes if this bothers you
var itemSql = new SqlStatement(connectionStringName);
itemSql.Add(string.Format("SELECT {0}, {1} ", OrderItemsTable.COLUMN_LIST, ProductsTable.COLUMN_LIST));
itemSql.InnerJoin(
OrderItemsTable.TABLE_NAME,
OrderItemsTable.ColumnsQualified.SKU,
ProductsTable.TABLE_NAME,
ProductsTable.ColumnsQualified.SKU)
.Where(OrderItemsTable.Columns.OrderID, orderID);
batch.Append(itemSql);
var cmd = batch.BuildCommand(connectionStringName);
using (var rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)) {
//customer
if (rdr.Read()) {
result = new Customer(userName,
CustomersTable.ReadEmail(rdr),
CustomersTable.ReadFirst(rdr),
CustomersTable.ReadLast(rdr));
} else {
result = new Customer();
}
//address
result.AddressBook = new List<Address>();
if (rdr.NextResult()) {
while (rdr.Read()) {
result.AddressBook.Add(LoadAddress(rdr));
}
}
//cart
result.Cart = new ShoppingCart(userName);
if (rdr.NextResult()) {
if (rdr.Read()) {
result.Cart.ShippingAddress = result.AddressBook.SingleOrDefault(x => x.AddressID == OrdersTable.ReadShippingAddressID(rdr));
result.Cart.BillingAddress = result.AddressBook.SingleOrDefault(x => x.AddressID == OrdersTable.ReadBillingAddressID(rdr));
result.Cart.ShippingService = OrdersTable.ReadShippingService(rdr) ?? "";
result.Cart.ShippingAmount = OrdersTable.ReadShippingAmount(rdr);
result.Cart.TaxAmount = OrdersTable.ReadTaxAmount(rdr);
}
}
//items
if (rdr.NextResult()) {
while (rdr.Read()) {
var product = productRepo.LoadProduct(rdr);
result.Cart.Items.Add(new ShoppingCartItem(product, CartItemsTable.ReadQuantity(rdr), CartItemsTable.ReadDateAdded(rdr)));
}
}
}
return result;
}