Пример #1
0
 public void Save(OrderContent oContent)
 {
     using (var context = new MASContext())
     {
         //context.Ord
         context.SaveChanges();
     }
 }
Пример #2
0
        public void a()
        {
            using (var context = new MASContext())
            {
                var contract = context.Contracts.Include(a => a.ContractIngredients).First(b => b.Id == 1);
                if (contract == null)
                {
                    throw new Exception("nie działa");
                }
                var i1  = new Ingredient("Chleb", 10.00m);
                var i2  = new Ingredient("Ser", 19.00m);
                var i3  = new Ingredient("Wołowina", 34.00m);
                var i4  = new Ingredient("Sałata", 5.00m);
                var ic1 = new ContractIngredient();

                using (var tran = context.Database.BeginTransaction())
                {
                    try
                    {
                        context.Update(contract);
                        context.SaveChanges();

                        context.Ingredients.Add(i1);
                        context.Ingredients.Add(i2);
                        context.Ingredients.Add(i3);
                        context.Ingredients.Add(i4);
                        context.SaveChanges();

                        context.ContractIngredients.Add(new ContractIngredient(contract, i1));
                        context.ContractIngredients.Add(new ContractIngredient(contract, i2));
                        context.ContractIngredients.Add(new ContractIngredient(contract, i3));
                        context.ContractIngredients.Add(new ContractIngredient(contract, i4));
                        context.SaveChanges();
                        tran.Commit();
                    }
                    catch (Exception)
                    {
                        tran.Rollback();
                    }
                }
                context.SaveChanges();
            }
        }