private void DeleteChildProductExample() { try { using (var context = new AdventureWorks2012Entities1()) { var prod = context.Products.Where(p => p.ProductNumber == "IKAYA-R209").First(); context.DeleteObject(prod); context.SaveChanges(); } } catch (Exception ex) { MessageBox.Show(ex.InnerException.Message); } }
private void AddProductModelMethodTwo() { try { using (var context = new AdventureWorks2012Entities1()) { var productModel = ProductModel.CreateProductModel(0, "Rear Shock", Guid.NewGuid(), DateTime.Now); context.AddToProductModels(productModel); context.SaveChanges(); label1.Text = "Save successful"; } } catch (Exception ex) { MessageBox.Show(ex.Message); throw; } }
private void AddProductModelMethodOne() { try { using (var context = new AdventureWorks2012Entities1()) { var productModel = new ProductModel(); productModel.Name = "Front Forks"; productModel.rowguid = Guid.NewGuid(); productModel.ModifiedDate = DateTime.Now; context.ProductModels.AddObject(productModel); context.SaveChanges(); label1.Text = "Save successful"; } } catch (Exception ex) { MessageBox.Show(ex.Message); throw; } }
private void AddChildProductExample() { try { using (var context = new AdventureWorks2012Entities1()) { var prodMod = context.ProductModels.Where(pm => pm.ProductModelID == 129).First(); var prod = new Product(); prod.Name = "Inverted Kayaba"; prod.ProductNumber = "IKAYA-R209"; prod.MakeFlag = true; prod.FinishedGoodsFlag = true; prod.Color = "Red"; prod.SafetyStockLevel = 250; prod.ReorderPoint = 250; prod.StandardCost = 2500; prod.ListPrice = 3900; prod.Size = "40M"; prod.SizeUnitMeasureCode = "CM"; prod.WeightUnitMeasureCode = "LB"; prod.Weight = (decimal)45.2; prod.DaysToManufacture = 5; prod.ProductLine = "S"; prod.Class = "M"; prod.Style = "M"; prod.ProductSubcategoryID = 1; prod.SellStartDate = DateTime.Now; prod.ModifiedDate = DateTime.Now; prod.rowguid = Guid.NewGuid(); prod.ProductModel = prodMod; context.SaveChanges(); label1.Text = "Save successful"; } } catch (Exception ex) { MessageBox.Show(ex.InnerException.Message); } }