I'm experiencing issues deleting parent objects in an object graph using breeze, when there are complex graphs of children involved. Every time I try to delete a parent, I get foreign key conflicts, even if there is only one simple child. Any advice? Before I post code here, I'd like to understand existing issues I should be aware of. My breeze controller is working with EF6.
Asked
Active
Viewed 56 times
1 Answers
0
The reason you are getting the error is because you have a foreign key constraint. In your code-first DBContext you establish a relationship between a parent and a child and you probably aren't telling EF what to do in case of deletion.
You can either enable the cascading deletes, or set the rules however you want using Fluent API. Check this answer for more details -
Cascade Delete Rule in EF 4.1 Code First when using Shared Primary Key Association
-
Nope, I implemented the following in my DbContext, but still get the error on delete... protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity
() .HasMany(dc => dc.BusinessUnits) .WithRequired(bu => bu.DashboardConfiguration) .WillCascadeOnDelete(); } – zpydee Jan 27 '14 at 07:12 -
the only way I can get rid of the error is by deleting the navigation property on the child. interestingly, i've used the same bidirectional setup between the child and grandchildren, but get no foreign key error with those entities. – zpydee Jan 27 '14 at 08:05