コード例 #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 CustomersRepository(CustomersDbContext context, ILoggerFactory loggerFactory)
 {
     _context = context;
     _logger  = loggerFactory.CreateLogger("CustomersRepository");
 }