Rebuilding links from database

I am saving goIconicNodes, goSimpleNodes, goBalloons and goLinks in an sql data base and the data looks correct. Lets say I add a flowmeter and a blower, both simple nodes. In the created data, the partid on the flowmeter is 0, blower is 3. I then link from the flow to the blow and the partid for the link is 6 and the fromport is 2 and the toport is 4. That all makes sence numerically (I think).
When I reload the data, I do a foreach loop and add the nodes (skiping the links)–all goes well they are there and in the correct position, etc.
Next, I do a foreach loop to add links (same loop can add balloons, but not that far yet). When the I get to the code:
pid = Convert.ToInt16(dr[“nFromPort”].ToString());
l.FromPort = (IGoPort)MyView.Document.FindPart(pid);
pid = Convert.ToInt16(dr[“nToPort”].ToString());
l.ToPort = (IGoPort)MyView.Document.FindPart(pid);

I break and the pid value for the fromport is 2 and the toport is 4, but the 2nd and 4th line return a null to l.FromPort and l.ToPort. So the link either is not added or does not appear to be there because it couldn’t find the ports. As usuall, I’m missing something.
Thanks for your help.
Mark

First, I strongly recommend using 32 bits for the IDs.
Second, when you load (i.e. reconstruct) the nodes, are you also assigning the node and port PartIDs before you add the node to the document?

I am assigning the partid of the node in the following code of a switch statement inside a foreach loop:
case “goSimpleNode”:

GoSimpleNode sn = new GoSimpleNode();
sn.Initialize(null, "blowerleft", "Blower 2");
sn.PartID = (int)dr["nPartID"];
sn.MinimumIconSize = new SizeF(48, 48);
sn.Left = (float)x;
sn.Top = (float)y;
sn.Image.Name = dr["nImage"].ToString();
sn.Text = dr["nText"].ToString();
sn.Width = (float)w;
sn.Height = (float)h;
MyView.Document.Add(sn);
break;
So I guess the answer is no. I thought that the ports would get assigned the same partids as when I origianally added them manually because I couldn't see any way to physically assign the port partids. And I will change to in32s.

No, IGoIdentifiablePart.PartID defaults to -1.
So you should do something like:
sn.InPort.PartID = (int)dr[“nInputPartID”];
sn.OutPort.PartID = (int)dr[“nOutputPartID”];
Of course, you need to save those two PartIDs too.

By the way, you might encounter a problem with nodes apparently shifting between saving and loading. That’s because you are setting the GoObject.Left and .Top properties before changing some of the other properties (such as the GoImage and GoText properties) that will change the size of the node. It would be easiest to set the Position properties last.

I have done more research and I think I got confused by looking at the flowchart example and the top, bottom, right, left ports there. I now see in the reference manual “port” for iconic nodes, and “inport” and “outport” for simple nodes. So If I save the partids of those, and recreate them on the rebuild, then I should have the partids to use with the FindPart function. Yes?
Mark

Yes!

Walter, I appreciate all your help. I wanted to post a resolution to this here in case others review this in the future.
The first problem that I had was that I was not saving off the “port” value of the iconic node or the in and out port values of the simple node. HOWEVER, after I fixed that it still didn’t work. Walter looked at the code and then pointed out that “maintainsPartID” was not set to true. I was apparently setting that after the rebuild code occured which messed badly with my attemped port assignments. So I simply turned on “MaintainsPartID” for the document BEFORE I started trying to put my nodes and links on.
Thanks again for the help!