Child object INSERT fails with Foreign Key Constraint violation, but why?

Child object INSERT fails with Foreign Key Constraint violation, but why?

Old forum URL: forums.lhotka.net/forums/t/9772.aspx


loch006 posted on Tuesday, November 16, 2010

I have an object structure that looks like this (using CSLA 4.0.1)

Entity
--- ProcessList (of Process objects)
------ProcessAccountList (list of ProcessAccount objects)
----------SystemData object (single child, all ProcessAccount objects have one instance of SystemData)

 

The Entity insert goes fine, FieldManager.UpdateChildren() is called on Entity which causes the  the list (currently with one Process object) to fire off Child_Insert(), which succeeds and then calls its own FieldManager.UpdateChildren(). That in turn triggers a Child_Insert on the list of ProcessAccount objects (currently only one in the list) and that insert succeeds as well.

I call FieldManager.UpdateChildren() on the ProcessAccount's Child_Insert() method which triggers Child_Insert() on the SystemData object. That INSERT fails saying the ProcessAccountId from the parent object (ProccessAccount) does not yet exist.

 

I've checked my parameters and verified the constraints on relationships in the database are ok. Why would this be failing?

 

xAvailx replied on Tuesday, November 16, 2010

Setup a sql profile trace and find out what is getting sent over to the db. That may help you narrow down the issue..

loch006 replied on Tuesday, November 16, 2010

i am setting up the trace now and will post back with my findings

loch006 replied on Tuesday, November 16, 2010

thanks Avail, the trace actually helped a lot

after running it and watching the error codes come back after a certain SP executes i went back and checked out the way the foreign key was setup and sure enough, a relationship was pointing to the wrong key, which at that point wouldn't yet exist and is not part of the standard update chain based on the object graph

thanks again!

Copyright (c) Marimer LLC