Entity Framework 4 executes stored procedures for an insert operation in the wrong order when a multi-level parent child relationship exists

We are faced with an incomprehensible problem with Entity Framework 4. Our model contains an object that is associated with 3 entities, let's call them first-level children. One of the children is associated with another entity - let him call it a second-level child.

All of these 5 objects are mapped to stored procedures to perform insert, update, and delete.

Before matching stored procedures, the order of the insert requests issued by the entity framework was correct. A first request to enter the table is issued, then an insert request is issued for children of the first level, and finally, an insert request is issued for the child of the second level.

But after matching stored procedures, the entity infrastructure sends the stored procedure statements in the wrong order - the first stored procedure inserts the first main table, and then the stored procedures for 2 children of the first level (which are not parents of the child of the second level) are inserted, then the stored procedure of the second level ( for several records) and, finally, the stored procedure for inserting the remaining child level of the first level, which is the parent of the second level.

This poses a problem because a second-level child insert before its parent insert violates the foreign key.

When you remove the display of a stored procedure for a table that is a parent of a second level, it works without problems.

- , SQL, ?

+3

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


All Articles