Looks like the override method is not working.
Update your code to:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Channel>()
.HasMany(c=>c.BusUnitChannels)
.WithRequired(buc=>buc.Channel)
.WillCascadeOnDelete();
base.OnModelCreating(modelBuilder);
}
or better yet; Set the delete cascade rule in your database. That's the way I prefer it.
Edit:
I have tested the code and it worked: Modify BusUnitChannel class as follows:
public class BusUnitChannel
{
public int Id { get; set; }
public int BusinessUnitId { get; set; }
[ForeignKey("Channel")]
public int ChannelId { get; set; }
public BusinessUnit BusinessUnit { get; set; }
public virtual Channel Channel { get; set; }
}
To set a cascade delete in SQL Server:
expand "BusUnitChannel" table; you'll find the FK constraint under "Keys".Right Click then Modify. a dialog will show; expand "Insert and Update specification"change the "Delete Rule" to "Cascade" You can set the update rule as well.