Moving Entity to another EntityCollection

Posts   
 
    
Nill
User
Posts: 7
Joined: 11-Oct-2006
# Posted on: 21-Dec-2006 09:47:16   

I have an EntityCollection<MasterEntity> (Masters) where each MasterEntity has an EntityCollection<ChildEntity> (Masters[i].Child).

The data already exists on the database and has been loaded with a single fetch by using a prefetch path.

How do I move Masters[0].Child[0] to the Masters[1].Child collection?

The following code moves the ChildEntity from Masters[0].Child to Masters[1].Child. However, the foreign key field (ChildEntity.MasterId) hasn't changed. It's still got the value of Masters[0].MasterId.

//Move a ChildEntity from Masters[0].Child to Masters[1].Child.
Masters[0].Child[0].Master = Masters[1];
//Now the ChildEntity has been removed from the Masters[0].Child collection and added to Masters[1].Child.
//However, the ChildEntity's MasterId-field still has the value of Masters[0].MasterId.

I've been looking at the documentation (Using the generated code | Adapter | Using the entity classes | FK-PK synchronization) and searched the forum but haven't figured out how to make it work.


Edit: Hmm, it seems that I sometimes get the correct behavior. So maybe I'm moving the entity the correct way. Thus, it seems that I'm doing something wrong somewhere in my code. Please don't spend time looking into this matter as it would probably require my whole code.