views:

58

answers:

0

Hi,

We are encountering a strange problem with Entity Framework 4. Our model contains an entity which is associated with 3 entities, let us call them first level children. One of the child entity is associated to another entity - let's call this as second level child.

All these 5 entities are mapped to stored procedures for performing insert, update and delete.

Before mapping the stored procedures the order of insert queries issued by entity framework was correct - First main table's insert query is issued, then the insert query for first level children is issued and finally the insert query for second level child is issued.

But after mapping the stored procedures, entity framework is sending the execute stored procedure statements in wrong order - first main table's insert stored procedure followed by insert stored procedures for 2 first level children (which are not parent of second level child), then second level child' stored procedure(s) (for multiple records) and finally the insert stored procedure of remaining first level child which is parent of second level child.

This creates a problem as the second level child's insert before its parent insertion results in foreign key violation.

On removing the stored procedure mapping for table which is parent of second level child, it works without problem.

Anybody has some idea on what determines the order of SQL statements generated by entity framework?