one new IPrefetchPath2 record please

Posts   
 
    
7zark7
User
Posts: 4
Joined: 21-Aug-2006
# Posted on: 21-Aug-2006 06:59:53   

i would like to create a new record with an entity that has several prefetch paths connected to it.

so basically i would like to create a new entity

BlahEntity blah = new BlahEntiy(idblah);

......set the prefetch paths.......

null the PK on blah

and insert a new record for the blahEntity so i hopefully get a new record in the table blah and new records in the prefetch path tables that are linked to the new PK.

so in the database i would end up with

the old record Blah and associated links, etc

a new record in Blah with new associated links but the same table content as the old record..

i hope i have explained my intentions appropriatly,

any help would be appreciated.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-Aug-2006 09:02:12   

PrefetchPaths are used for fetching related entities only.

Are you trying to insert an entity with some related entities as well (a graph) that have the same field values as already existing entities?

7zark7
User
Posts: 4
Joined: 21-Aug-2006
# Posted on: 21-Aug-2006 09:14:37   

i am not sure what a graph is, so i will attempt to explain this in a little more depth

table ABC ABC.idabc = 1 ABC.name = "stuff" etc

there is a prefetch path to a number of other tables, however in this example i will use only one

prefetchpath from ABC to XYZ

XYZ.idxyz = 88 XYZ.fkabc = 1 XYZ.otherstuff = "blah" etc...

ok what i want to do is take the record ABC where ABC.idabc = 1 take all the prefetch tables.

create a new record based on these details, so i get table ABC new record ABC.idabc = 2 ABC.name = "stuff" etc

there is a prefetch path to a number of other tables, however in this example i will use only one

prefetchpath from ABC to XYZ

XYZ.idxyz = 89 XYZ.fkabc = 2 XYZ.otherstuff = "blah" **etc. **

mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 21-Aug-2006 09:38:26   

Create a new ABC entity instance, copy the data from original entity, and then do the same for XYZ in a loop. Something like this.

7zark7
User
Posts: 4
Joined: 21-Aug-2006
# Posted on: 22-Aug-2006 02:38:39   

thanks for the help,

however your post has not included the code stuck_out_tongue_winking_eye

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 22-Aug-2006 07:55:19   

So basicly all you want to do is to copy an entity with its related entities.


ABCEntity abcCopy = new ABCEntity();
abcCopy.name = ABC.name;
abcCopy.otherField = ABC.otherField;

XYZEntity xyz = new XYZEntity();
xyz.otherstuff1 = XYZ.otherstuff1;
xyz.otherstuff2 = XYZ.otherstuff2; 

abcCopy.XYZ = xyz;

//do the same for other related entities
// then save the abcCopy entity