I am using the entity framework with the first code and I have a problem with the removal of the cascade. Since my model is not small, I need to turn it off, because otherwise the circular has to be deleted, which could not be solved by SQL Server.
modelbuilder.Conventions.Remove & lt; OneToManyCascadeDeleteConvention & gt; (); ModelBuilder.Conventions.Remove & LT; ManyToManyCascadeDeleteConvention & gt; (); After this, it has been specified manually which organizations should be removed using Fluent API, such as: modelbuilder.Entity & Lt; First & gt; (). HasRequired (x = & gt; x.Second). many of (). WillCascadeOnDelete (true);
However, I'm having problems during testing.
How does the model look here represent the letters A to F institutions and the arrow points to the next unit which should be removed in the series (like a tree, but I explained that where the problem is).
The problem is that one unit can not be destroyed in the middle because at the end one unit is a foreign key for the unit in the middle. However, both organizations will be destroyed anyway, SQL Server refuses to delete.
- A - Cascade -> B
- B - Cascade -> C
- C - Waterfall -> D
- C
- E - Cascade -> F Here's a picture to make it easier to understand:
When I try to delete the unit "A", I get the following message:
This DELETE statement Contrary to context reference, \ "FK_dbo.F_dbo.D_Id \"
This is very annoying, because SQL Server is able to find out Shm should be "D" and "F" both made the request to remove can be removed safely when A.
How do you solve this problem? Keep in mind that the model is slightly more complicated than this and similar cases get the thought model again. You can assume that there is no circular cached data in the model because such cases are presented manually.
I do not understand what your last sentence is saying because your problem OK < / Em> is that you have a circular dependency in your model: D -> E -> F -> D
Since the integrity referred to is always protected There is no way that your delivery can be successful until the circular dependence is there. If it can be broken by excluding FC connection, for example, DIID can be removed in every F line, then it is zero. This will work when the work is finished for the rows affecting the circular.
Circular dependency is not a good sign of quality design, I urge you to reconsider it.
No comments:
Post a Comment