예제 #1
0
        internal EntityEntry DeleteEntity()
        {
            Console.WriteLine("*** Delete Entity *** ");
            var person = _context.Person.Find(1);

            //This isnt in memory => retrieved from database
            _context.Entry(person).State = EntityState.Deleted;
            //This must be in memory => retrieved from database
            _context.Person.Remove(person);
            _context.SaveChanges();
            return(_context.ChangeTracker.Entries().First());
        }
예제 #2
0
        public bool UpdateProductQuantity(ProductInventoryUpdateModel updateModel)
        {
            var data = _db.Product.Find(updateModel.ProductId);

            data.Quantity = updateModel.Quantity;

            _db.SaveChanges();

            return(true);
        }
예제 #3
0
        public void AddAnItem()
        {
            ShouldExecuteInATransaction(AddNewPerson);
            void AddNewPerson()
            {
                var person = new Person
                {
                    AdditionalContactInfo = "Home",
                    FirstName             = "Barney",
                    LastName = "Rubble",
                    Title    = "Neighbor"
                };

                _context.Person.Add(person);
                _context.SaveChanges();
            }
        }
예제 #4
0
        private void PrepareData()
        {
            if (!_awDbContext.Product.Any())
            {
                var catgories = new List <ProductCategory>
                {
                    new ProductCategory {
                        ProductCategoryId = 1, Name = "MyCat1"
                    },
                    new ProductCategory {
                        ProductCategoryId = 2, Name = "MyCat2"
                    }
                };

                var subCategores = new List <ProductSubcategory>
                {
                    new ProductSubcategory {
                        ProductSubcategoryId = 1, ProductCategoryId = 1, Name = "MuSubCat1"
                    },
                    new ProductSubcategory {
                        ProductSubcategoryId = 2, ProductCategoryId = 2, Name = "MuSubCat2"
                    }
                };

                var products = new List <Product>
                {
                    new Product {
                        ProductId = 1, Name = "Product1", Quantity = 10, ProductSubcategoryId = 1
                    },
                    new Product {
                        ProductId = 2, Name = "Product2", Quantity = 20, ProductSubcategoryId = 2
                    }
                };

                _awDbContext.ProductCategory.AddRange(catgories);
                _awDbContext.ProductSubcategory.AddRange(subCategores);
                _awDbContext.Product.AddRange(products);

                _awDbContext.SaveChanges();
            }
        }
예제 #5
0
        public void AddAnItem()
        {
            //helper method
            ShouldExecuteInATransaction(AddNewPerson);

            //local function
            void AddNewPerson()
            {
                //INSERT INTO PERSON and just these fields right here
                //Also executes in server side things "row verison"
                var person = new Person
                {
                    AdditionalContactInfo = "Home",
                    FirstName             = "Fname",
                    LastName = "Lname",
                    Title    = "Neighbor"
                };

                _context.Person.Add(person);
                _context.SaveChanges();
            }
        }