Relation problem

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

Hi,

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

Entity1---Entity2---Entity3---Entity4

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 :

             |---Entity2---|

Entity1---|                |---Entity4

             |--Entity3---|

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?

Coordinator
May 10, 2010 at 2:27 AM

Hi,

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.

-Christian

May 10, 2010 at 3:42 PM

Hi,

 

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?

Coordinator
May 13, 2010 at 4: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...