コード例 #1
0
        public static void Initialize(DepartmentAPIContext context)
        {
            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            // Look for any Products
            if (context.Departments.Any())
            {
                return;   // DB has been seeded
            }

            List <Department> deps = new List <Department>
            {
                new Department {
                    Id = 1, Name = "IT"
                },
                new Department {
                    Id = 2, Name = "Administration"
                },
            };

            context.Departments.AddRange(deps);
            context.SaveChanges();
        }
コード例 #2
0
 public DepartmentRepository(DepartmentAPIContext context)
 {
     db = context;
     db.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
 }