Exemple #1
0
        public static void AddData1(CustomerOrderContext db)
        {
            for (int id = 0; id < 100; id++)
            {
                var balance = id;
                // EF detects each of these as a discrete change, and processes in the insert statements one at a time
                var customer = new Customer
                {
                    Name    = $"Customer Name",
                    Balance = balance
                };

                db.Customers.Attach(customer);
                db.Entry(customer).State = EntityState.Added;
                db.Entry(customer).State = EntityState.Modified;
                db.Entry(customer).State = EntityState.Deleted;
            }

            db.SaveChanges();
        }
Exemple #2
0
        public async Task Update(TModel entity)
        {
            var stored = await _customerOrderContext.FindAsync <TModel>(entity.Id);

            if (stored == null)
            {
                return;
            }

            _customerOrderContext.Entry(stored).CurrentValues.SetValues(entity);
            await _customerOrderContext.SaveChangesAsync();
        }
Exemple #3
0
        public static void Delete1(CustomerOrderContext db)
        {
            var customers = db.Customers
                            .AsNoTracking()
                            .OrderByDescending(x => x.Id)
                            .Take(100)
                            .ToList();

            foreach (var customer in customers)
            {
                db.Customers.Attach(customer);
                db.Entry(customer).State = EntityState.Deleted;
            }
        }
Exemple #4
0
        public static void Delete1(CustomerOrderContext db)
        {
            var customerIds = db.Customers
                              .OrderByDescending(x => x.Id)
                              .Select(x => x.Id)
                              .Take(100)
                              .ToList();

            foreach (var id in customerIds)
            {
                var customer = new Customer()
                {
                    Id = id
                };
                db.Customers.Attach(customer);
                db.Entry(customer).State = EntityState.Deleted;
            }
        }