Esempio n. 1
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasDefaultSchema("efcore");

            CategoryConfiguration.Configure(modelBuilder.Entity <Category>());
            ShipperConfiguration.Configure(modelBuilder.Entity <Shipper>());
            RegionConfiguration.Configure(modelBuilder.Entity <Region>());
            SupplierConfiguration.Configure(modelBuilder.Entity <Supplier>());
            EmployeeConfiguration.Configure(modelBuilder.Entity <Employee>());
            CustomerDemographicsConfiguration.Configure(modelBuilder.Entity <CustomerDemoGraphic>());
            CustomerConfiguration.Configure(modelBuilder.Entity <Customer>());
            OrderConfiguration.Configure(modelBuilder.Entity <Order>());
            ProductConfiguration.Configure(modelBuilder.Entity <Product>());
            TerritoryConfiguration.Configure(modelBuilder.Entity <Territories>());
            EmployeeTerritoryConfiguration.Configure(modelBuilder.Entity <EmployeeTerritories>());
            CustomerCustomerDemographConfiguration.Configure(modelBuilder.Entity <CustomerCustomerDemograph>());
            OrderDetailConfiguration.Configure(modelBuilder.Entity <OrderDetail>());

            base.OnModelCreating(modelBuilder);
        }
Esempio n. 2
0
        protected override void OnModelCreating(ModelBuilder builder)
        {
            CustomerConfiguration.Configure(builder);
            OrderConfiguration.Configure(builder);

            base.OnModelCreating(builder);

            var entityTypes = builder.Model
                              .GetEntityTypes()
                              .ToList();

            // Set global query filter for not deleted entities only

            // Disable cascade delete
            var foreignKeys = entityTypes
                              .SelectMany(e => e.GetForeignKeys()
                                          .Where(f => f.DeleteBehavior == DeleteBehavior.Cascade));

            foreach (var foreignKey in foreignKeys)
            {
                foreignKey.DeleteBehavior = DeleteBehavior.Restrict;
            }
        }