コード例 #1
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using var context = new HahnDbContext(
                      serviceProvider.GetRequiredService <DbContextOptions <HahnDbContext> >()
                      );

            // Look for any department.
            if (context.Department.Any())
            {
                return; // Data was already seeded
            }

            context.Department.AddRange(
                new Department {
                ID = DepartmentEnum.HQ, Name = "HQ"
            },
                new Department {
                ID = DepartmentEnum.MantenanceStation, Name = "Mantenance Station"
            },
                new Department {
                ID = DepartmentEnum.Store1, Name = "Store 1"
            },
                new Department {
                ID = DepartmentEnum.Store2, Name = "Store 2"
            },
                new Department {
                ID = DepartmentEnum.Store3, Name = "Store 3"
            }
                );

            context.SaveChanges();
        }
コード例 #2
0
        public void PopulateInitialData()
        {
            var applicants = new List <Applicant> {
                new Applicant
                {
                    ID              = 1,
                    Name            = "Arvind",
                    FamilyName      = "Kumar",
                    Address         = "M G Road, Bangalore",
                    Age             = 35,
                    CountryOfOrigin = "India",
                    EmailAddress    = "*****@*****.**",
                    Hired           = false
                },
                new Applicant
                {
                    ID              = 2,
                    Name            = "Steve",
                    FamilyName      = "Martin",
                    Address         = "5th Ave, Las Vegas",
                    Age             = 32,
                    CountryOfOrigin = "United States of America",
                    EmailAddress    = "*****@*****.**",
                    Hired           = false
                },
                new Applicant
                {
                    ID              = 3,
                    Name            = "Bjorn",
                    FamilyName      = "Hough",
                    Address         = "Kuholmsveien Kristiansand",
                    Age             = 40,
                    CountryOfOrigin = "Lund",
                    EmailAddress    = "*****@*****.**",
                    Hired           = false
                }
            };

            dbContext.Applicants.AddRange(applicants);

            dbContext.SaveChanges();
        }
コード例 #3
0
        //public IRepository<Book> BookRepository
        //{
        //    get { return _bookRepository = _bookRepository ?? new Repository<Book>(_databaseContext); }
        //}

        public void Commit()
        {
            _databaseContext.SaveChanges();
        }
コード例 #4
0
 public int Save()
 {
     return(_db.SaveChanges());
 }