コード例 #1
0
        public async Task InsertCustomersSampleData(CustomersDbContext db)
        {
            var states = GetStates();

            db.States.AddRange(states);
            try
            {
                await db.SaveChangesAsync();
            }
            catch (Exception exp)
            {
                _logger.LogError($"Error in {nameof(CustomersDbSeeder)}: " + exp.Message);
                throw;
            }

            var customers = GetCustomers(states);

            db.Customers.AddRange(customers);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (Exception exp)
            {
                _logger.LogError($"Error in {nameof(CustomersDbSeeder)}: " + exp.Message);
                throw;
            }
        }
コード例 #2
0
        public async Task <Customer> InsertCustomerAsync(Customer customer)
        {
            _context.Add(customer);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (System.Exception exp)
            {
                _logger.LogError($"Error in {nameof(InsertCustomerAsync)}: " + exp.Message);
            }

            return(customer);
        }