AssocAddEdit.Models.DataContext.OnModelCreating C# (CSharp) Метод

OnModelCreating() защищенный Метод

protected OnModelCreating ( DbModelBuilder modelBuilder ) : void
modelBuilder DbModelBuilder
Результат void
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            // The default behaviour for the one (Manufacturer) to many (Vehicles)
            // association is "cascade delete"
            // This means that deleting a Manufacturer will cause the Vehicles to be deleted
            // In this code example, we do NOT want that behaviour

            // We cannot do this with a data annotation
            // We must use this Fluent API

            // First, call the base OnModelCreating method,
            // which uses the existing class definitions and conventions

            base.OnModelCreating(modelBuilder);

            // Then, change the "cascade delete" setting
            // This can be done in at least two ways; un-comment the desired code

            // Alternative #1
            // Turn off "cascade delete" for all default convention-based associations

            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();

            // Alternative #2
            // Turn off "cascade delete" for a specific association

            //modelBuilder.Entity<Vehicle>()
            //    .HasRequired(m => m.Manufacturer)
            //    .WithMany(v => v.Vehicles)
            //    .WillCascadeOnDelete(false);
        }