Entity Framework - dependent objects not deleted to the main object when the cascade deleting compound key objects

I had a problem with cascading deletion of dependent objects with compound keys . In particular, the emitted SQL EF commands try to remove the main entity before the dependent object.

I have OnDelete="Cascade"one installed in both CSDL and SSDL of my EF model and I explicitly load the dependent objects into memory, so EF knows how to deal with them. I work correctly with other FK relationships, and EF correctly removes child objects before deleting the principle.

However, this is not so, and I suspect, because the dependent object has a composite key. Brief overview of the scheme:

Entity A              Entity B                 Entity A_B
  ID (PK)               ID (PK)                  A_ID  (PK, FK to A)
                                                 B_ID  (PK, FK to B)

I want Entity A_B entries to be deleted when I delete Entity A.

I can look into the ObjectStateManager and see A_B objects loaded into memory and marked for deletion, but EF emits an SQL command to delete A before deleting its A_Bs. This works great when the dependent object has its own PC, but it seems to work when it is a composite key. At first, he does not remove children, even if I directly say to the EF FK Association (both SSDL and CSDL) that Deletes should be cascaded.

Again, I have both A and its A_Bs loaded into memory, and the ObjectStateManager has everything marked for deletion. I use POCOs with Proxy Creation support, although I explicitly load child entities into memory through calls to LoadProperty versus Context.

- ? ? EF SQL , ?


EDIT: OnDelete (http://msdn.microsoft.com/en-us/library/cc716734.aspx), (http://msdn.microsoft.com/en-us/library/ee373856.aspx). , " ", , , , , . EF ? Informix IBM.Data.DB2 SQL Server.

( :. IBM DB2 v9.7fp3a EF Providers Beta Refresh - http://www.ibm.com/developerworks/forums/thread.jspa?threadID=345634&tstart=0)

+3
1

, - . , Sql Profiler DB2... db , . , , .

0

Source: https://habr.com/ru/post/1776559/


All Articles