Some confuse about inheritance

Oct 27, 2011 at 7:16 AM

My data structure is the following as ..
Parent Table Schema is 
HVDiagram      GroupId (int)      ID (int, Primary Key)      NodeName (int)      NodeType (int)      ParentId (int)

Two Child Tables Schema are
HVLA      ID (int)      V  (single)
HVLBS      IC (single)      ID (int)      POFAT (single)      POFIC (single)

I create a subdomain explicitly to insert data in one transaction.

SubDomain subdomain = new SubDomain();

HVDiagramCollection panelISOCollection = (HVDiagramCollection)subdomain[Collections.HVDiagramCollection];HVDiagram panelISO = panelISOCollection.NewItem();
panelISO.NodeName = 'Panel1';
panelISO.GroupId = 1000;
panelISO.NodeType = 'Panel';
panelISO.ParentId = 1;

panelISOCollection.AddItem(panelISO);

HVLACollection laCollection = (HVLACollection)subdomain[Collections.HVLACollection];HVLA la = laCollection.NewItem();
la.GroupId = 1000;
la.NodeType = 'LA';
la.ParentId = 1;
la.NodeName = 'LA1';

la.V = 0;
la.I = 0;

laCollection.AddItem(la);

HVLBSCollection lbsCollection = (HVLBSCollection)subdomain[Collections.HVLBSCollection];HVLBS lbs = lbsCollection.NewItem();
lbs.GroupId = 1000;
lbs.NodeType = 'LBS';
lbs.ParentId = 1;

lbs.AT = 0;
lbs.IC = 0;
lbs.NodeName = 'LBS1';
lbs.POFAT = 0;
lbs.POFIC = 0;
lbsCollection.AddItem(lbs);

subdomain.Persist();

There are three new records  in the Parent Table is ...

GroupId      ID       NodeName       NodeType       ParentId
1000           21      LBS1                 LBS                  1
1000           22      LBS1                 LBS                  1
1000           23      LBS1                 LBS                  1


Not is (This is the correct result.)
GroupId      ID      NodeName      NodeType      ParentId
1000           21     Panel1              Panel             1
1000           22     LA1                  LA                  1
1000           23     LBS1                LBS                 1


The two child tables have correct data.


Why ? No Error Occurred.

Coordinator
Nov 13, 2011 at 1:04 PM

Please send your model to chrisd@nhydrate.org. I will run your code here and determine what is going on.

Nov 13, 2011 at 11:33 PM

I change my codes as the following and it worked fine.

SubDomain subdomain = new SubDomain();

HVDiagramCollection panelISOCollection = (HVDiagramCollection)subdomain[Collections.HVDiagramCollection];

HVDiagram panelISO = panelISOCollection.NewItem(1); //unique number 1
panelISO.NodeName = 'Panel1';
panelISO.GroupId = 1000;
panelISO.NodeType = 'Panel';
panelISO.ParentId = 1;


panelISOCollection.AddItem(panelISO);

HVLACollection laCollection = (HVLACollection)subdomain[Collections.HVLACollection];
HVLA la = laCollection.NewItem(2); //unique number 2
la.GroupId = 1000;
la.NodeType = 'LA';
la.ParentId = 1;
la.NodeName = 'LA1';

la.V = 0;
la.I = 0;

laCollection.AddItem(la);

HVLBSCollection lbsCollection = (HVLBSCollection)subdomain[Collections.HVLBSCollection];
HVLBS lbs = lbsCollection.NewItem(3); //unique number 3
lbs.GroupId = 1000;
lbs.NodeType = 'LBS';
lbs.ParentId = 1;

lbs.AT = 0;
lbs.IC = 0;
lbs.NodeName = 'LBS1';
lbs.POFAT = 0;
lbs.POFIC = 0;
lbsCollection.AddItem(lbs);

//Set the new item ID to -1
if (subdomain.Tables["HVDiagramCollection"].Rows.Count>0 && subdomain.Tables["HVDiagramCollection"].Columns.Contains("ID"))

{
DataRow dRow in subdomain.Tables[HVDiagramCollection].Rows[0]["ID"]=-1;
}

if (subdomain.Tables["HVLACollection"].Rows.Count>0 && subdomain.Tables["HVLACollection"].Columns.Contains("ID"))
{
  DataRow dRow in subdomain.Tables[HVLACollection].Rows[0]["ID"]=-1;
}

if (subdomain.Tables["HVLBSCollection"].Rows.Count>0 && subdomain.Tables["HVLBSCollection"].Columns.Contains("ID"))
{
DataRow dRow in subdomain.Tables[HVLBSCollection].Rows[0]["ID"]=-1;
}

//Persist
subdomain.Persist();