static void Cleanup() { using (var context = new EFRecipesEntities()) { context.ExecuteStoreCommand("delete from chapter5.customeremail"); context.ExecuteStoreCommand("delete from chapter5.customer"); context.ExecuteStoreCommand("delete from chapter5.customertype"); } }
static void Cleanup() { using (var context = new EFRecipesEntities()) { context.ExecuteStoreCommand("delete from chapter6.EventOrganizer"); context.ExecuteStoreCommand("delete from chapter6.Event"); context.ExecuteStoreCommand("delete from chapter6.Organizer"); } }
static void Cleanup() { using (var context = new EFRecipesEntities()) { context.ExecuteStoreCommand("delete from chapter13.hourlyemployee"); context.ExecuteStoreCommand("delete from chapter13.salariedemployee"); context.ExecuteStoreCommand("delete from chapter13.employee"); } }
static void Cleanup() { using (var context = new EFRecipesEntities()) { context.ExecuteStoreCommand("delete from chapter8.orderdetail"); context.ExecuteStoreCommand("delete from chapter8.[order]"); context.ExecuteStoreCommand("delete from chapter8.product"); context.ExecuteStoreCommand("delete from chapter8.customer"); } }
static void Cleanup() { using (var context = new EFRecipesEntities()) { context.ExecuteStoreCommand("delete from chapter12.applicant"); } }
static void Cleanup() { using (var context = new EFRecipesEntities()) { context.ExecuteStoreCommand("delete from Chapter10.Customer"); } }
public Payment InsertPayment() { using (var context = new EFRecipesEntities()) { // delete previous text data context.ExecuteStoreCommand("delete from chapter9.payment"); context.ExecuteStoreCommand("delete from chapter9.invoice"); var payment = new Payment { Amount = 99.95M, Invoice = new Invoice { Description = "Auto Repair" } }; context.Payments.AddObject(payment); context.SaveChanges(); return(payment); } }
static void RunExample() { // insert a couple rows using (var context = new EFRecipesEntities()) { string sql = @"insert into Chapter3.Payment(Amount, Vendor) values (@Amount, @Vendor)"; var args = new DbParameter[] { new SqlParameter { ParameterName = "Amount", Value = 99.97M }, new SqlParameter { ParameterName = "Vendor", Value = "Ace Plumbing" } }; int rowCount = context.ExecuteStoreCommand(sql, args); args = new DbParameter[] { new SqlParameter { ParameterName = "Amount", Value = 43.83M }, new SqlParameter { ParameterName = "Vendor", Value = "Joe's Trash Service" } }; rowCount += context.ExecuteStoreCommand(sql, args); Console.WriteLine("{0} rows inserted", rowCount.ToString()); } // materialize some entities using (var context = new EFRecipesEntities()) { Console.WriteLine("Payments"); Console.WriteLine("========"); foreach (var payment in context.Payments) { Console.WriteLine("Paid {0} to {1}", payment.Amount.ToString("C"), payment.Vendor); } } Console.WriteLine("Press <enter> to continue..."); Console.ReadLine(); }
protected void Page_Load(object sender, EventArgs e) { using (var context = new EFRecipesEntities()) { // delete any previous data we might have context.ExecuteStoreCommand("delete from chapter4.customer"); // insert some data context.Customers.AddObject(new Customer { Name = "Robin Rosen", City = "Olathe", State = "KS" }); context.Customers.AddObject(new Customer { Name = "John Wise", City = "Springtown", State = "TX" }); context.Customers.AddObject(new Customer { Name = "Karen Carter", City = "Raytown", State = "MO" }); context.SaveChanges(); } }
static void RunExample() { using (var context = new EFRecipesEntities()) { context.Products.AddObject(new Product { Name = "High Country Backpacking Tent", UnitPrice = 199.95M }); context.SaveChanges(); } using (var context = new EFRecipesEntities()) { // get the product var product = context.Products.SingleOrDefault(); Console.WriteLine("{0} Unit Price: {1}", product.Name, product.UnitPrice.ToString("C")); // delete out of band context.ExecuteStoreCommand(@"update chapter14.product set unitprice = 229.95 where productId = @p0", product.ProductId); // update the product the via the model product.UnitPrice = 239.95M; Console.WriteLine("Changing {0}'s Unit Price to: {1}", product.Name, product.UnitPrice.ToString("C")); try { context.SaveChanges(); } catch (OptimisticConcurrencyException ex) { Console.WriteLine("Concurrency Exception! {0}", ex.Message); } catch (Exception ex) { Console.WriteLine("Exception! {0}", ex.Message); } } Console.WriteLine("Press <enter> to continue..."); Console.ReadLine(); }