I have a system in ASP MVC with C # entity .
I have the table Pedidos
and Agenda
.
In the agenda
table I have a column with id
of the request.
When the request is canceled, I have to remove from the Agenda
table to release a time for a new request.
The problem is that when you remove the row from the Agenda
table with the request 13 (for example), the pedido
table is also removed.
I've already done a search and found something about Cascade
in SQL , but this is not enabled.
What can it be?
Follow the code below:
public partial class ifixEntities : DbContext
{
public MyEntities()
: base("name=MyEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();
modelBuilder.Entity<Agenda>().HasOptional<Pedido>(s => s.Pedido).WithMany().WillCascadeOnDelete(false);
}
}