public void ShouldConnectToShard() { //assemble var shardingKey = 1.ToString(CultureInfo.InvariantCulture); var connection = new ElasticSqlConnection("AWSales", shardingKey); using (connection) { connection.Open(); } }
public void AddTestDataInShardSet(string shardSetName, int initialTestCustomerID, int numberOfTestCustomers, int numberOfTestOrdersPerCustomer) { // set up header insert command for test data var headerInsertCommand = new SqlCommand("Sales.CreateSalesOrderHeader") { CommandType = CommandType.StoredProcedure }; var customerIDParameter = headerInsertCommand.Parameters.Add(new SqlParameter("CustomerID", SqlDbType.Int)); var headerSalesOrderIDParam = headerInsertCommand.Parameters.Add(new SqlParameter("SalesOrderID", SqlDbType.Int)); AddTestSalesOrderParametersTo(headerInsertCommand); // set up detail insert command for test data var detailInsertCommand = new SqlCommand("Sales.CreateSalesOrderLineItem") { CommandType = CommandType.StoredProcedure }; var detailSalesOrderIDParam = detailInsertCommand.Parameters.Add(new SqlParameter("SalesOrderID", SqlDbType.Int)); var salesOrderDetailLineNum = detailInsertCommand.Parameters.Add(new SqlParameter("SalesOrderLineNum", SqlDbType.Int)); AddTestSalesDetailParametersTo(detailInsertCommand); // set up shopping cart insert command for test data var shoppingCartItemInsertCommand = new SqlCommand("Sales.CreateShoppingCartItem") { CommandType = CommandType.StoredProcedure, }; var shoppingCartCustomerIDParameter = shoppingCartItemInsertCommand.Parameters.Add(new SqlParameter("CustomerID", SqlDbType.Int)); var shoppingCartLineNumParam = shoppingCartItemInsertCommand.Parameters.Add(new SqlParameter("ShoppingCartLineNum", SqlDbType.Int)); var quantityParam = shoppingCartItemInsertCommand.Parameters.Add(new SqlParameter("Quantity", SqlDbType.Int)); var productIDParam = shoppingCartItemInsertCommand.Parameters.Add(new SqlParameter("ProductID", SqlDbType.Int)); for (var customerID = initialTestCustomerID; customerID < numberOfTestCustomers + initialTestCustomerID; customerID++) { // get unique ids for sales orders var salesOrderIDList = GetUniqueSalesOrderIDs(numberOfTestOrdersPerCustomer); // the database is sharded on customer id var shardingKey = customerID.ToString(CultureInfo.InvariantCulture); // load the Shardlet object to the the appropriate connection string var connection = new ElasticSqlConnection(shardSetName, shardingKey); using (connection) { connection.Open(); foreach (var salesOrderID in salesOrderIDList) { // add sales order header headerInsertCommand.Connection = connection.Current; headerSalesOrderIDParam.Value = salesOrderID; customerIDParameter.Value = customerID; headerInsertCommand.ExecuteNonQuery(); // add sales order details detailInsertCommand.Connection = connection.Current; for (var i = 1; i < 5; i++) { detailSalesOrderIDParam.Value = salesOrderID; salesOrderDetailLineNum.Value = i; detailInsertCommand.ExecuteNonQuery(); } } // add shopping cart items shoppingCartItemInsertCommand.Connection = connection.Current; for (var i = 1; i < 5; i++) { shoppingCartCustomerIDParameter.Value = customerID; quantityParam.Value = i; productIDParam.Value = i; shoppingCartLineNumParam.Value = i; shoppingCartItemInsertCommand.ExecuteNonQuery(); } } } }