This project is read-only.

Relation problem

May 9, 2010 at 5:09 AM
Edited May 9, 2010 at 5:32 AM


I have had to change an relation that was implemented in this way:


And using that model, the only instruction that I did was context.PersistChanges<Entity1>(entity1) and the framework made all inserts of child objects from Entity1 to Entity4.

I had to change the relationship in this way :


Entity1---|                |---Entity4


But when I use the same instruction i get a foreign key exception because Entity4 needs that Entity2 and Entity3 are inserted before.

Now my question is:

What can I do to solve this problem in a trasparent way?

May 10, 2010 at 3:27 AM


this is not supported in automatic right now. It needs a bit of hand-holding by persisting first Entity 1 and Entity 4 and then the rest... You can achieve that by using the PersistChanges overload that takes the PersistDepths and using Flat as option.


May 10, 2010 at 4:42 PM



Thanks for reply,

In order to acomplish that I said, I need to insert Entity1, then Entity2, Entity3 and finaly Entity4.

So I should create a method that insert the object Entity1 and its childs manually.

Does OPF3 have any interface that I can use to acomplish that?

May 13, 2010 at 5:49 AM

You can insert the objects in a certain order by doing calling PeristChanges with the object and set Flat as the PersistDepth.

Additional you could implement the IRelationsNotification interface so you get a notification before a relationship gets walked and persisted. In that case you could persist the required objects (for that relationship) beforehand...