sohail.hussain.dyn
sohail.hussain.dyn

Reputation: 1541

code first cascade delete in config

Is there anyway to cascade delete false in the entity framework config settings. For now I have done using fluent API but there are multiple place where cascade delete need to be set false, so is there any single point where I can set for all classes, as I don't have any need of it.

Thanks.

Upvotes: 0

Views: 59

Answers (2)

Peter Barbanyaga
Peter Barbanyaga

Reputation: 536

public partial class MyContext : DbContext
{
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
    }

}

Upvotes: 2

Jay
Jay

Reputation: 3082

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); 

        //Set cascade options here also
    }

Upvotes: 0

Related Questions