Ok, sorry for long code but I prefer posting the real code.
Class A:
Code:
namespace SocomecDBBenchMark.NHibernateDatabaseStructure
{
/// <summary>
/// Summary description for CDevice
/// </summary>
public class CDevice
{
private string m_sID;
private string m_sType;
private string m_sName;
private ISet m_lMeasures;
public CDevice()
{
Name = "Unknown Device";
Type = "CDevice";
}
protected CDevice(string s_name)
{
Name = s_name;
}
public virtual ISet Measures
{
get
{
return m_lMeasures;
}
set
{
m_lMeasures = value;
}
}
public virtual string Id
{
get
{
return m_sID;
}
set
{
m_sID = value;
}
}
public virtual string Type
{
get
{
return m_sType;
}
set
{
m_sType = value;
}
}
public virtual string Name
{
get
{
return m_sName;
}
set
{
m_sName = value;
}
}
}
}
Class C : (I don't post the code for all inheritance graph : ExtendedDevice and CountisDevice and DirisDevice)
Code:
namespace SocomecDBBenchMark.NHibernateDatabaseStructure
{
/// <summary>
/// Summary description for CD18Device
/// </summary>
public class D18Device : DirisDevice // which inherits from ExtendedDevice which itself inherits from Device
{
private int IPPort; // not stored in db yet
private string IPAddress; // not stored in db yet
public D18Device()
{
}
public D18Device(string s_name)
: base(s_name, 1035)
{
}
public override string ToString()
{
return String.Format("{0} IPAddress={1}", base.ToString(), IPAddress);
}
}
}
Mapping for A (Device) and C (D18):
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<!-- ********************************************************************** -->
<!-- Device -->
<!-- -> ExtendedDevice -->
<!-- -> Diris -->
<!-- -> D18 -->
<!-- ********************************************************************** -->
<class name="SocomecDBBenchMark.NHibernateDatabaseStructure.CDevice" table="Device">
<!-- A 32 hex character is our surrogate key. It's automatically
generated by NHibernate with the UUID pattern. -->
<id name="Id">
<column name="ID" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex" />
</id>
<discriminator column="SUBCLASS" length="30"/>
<property name="Name">
<column name="Name" length="40" />
</property>
<property name="Type">
<column name="Type" length="50" />
</property>
<!-- Measures -->
<set name="Measures" inverse="true">
<key column="DEVICE_ID"/>
<one-to-many class="SocomecDBBenchMark.NHibernateDatabaseStructure.CMeasure"/>
</set>
<!-- Extended Device -> Device -->
<subclass name="SocomecDBBenchMark.NHibernateDatabaseStructure.ExtendedDevice" discriminator-value="Extended">
<property name="Weight" column="WEIGHT" />
<!-- DirisDevice -> Extended Device -->
<subclass name="SocomecDBBenchMark.NHibernateDatabaseStructure.DirisDevice" discriminator-value="Diris">
<!-- D18 -> DirisDevice -->
<subclass name="SocomecDBBenchMark.NHibernateDatabaseStructure.D18Device" discriminator-value="D18">
</subclass>
<!--
<property name="Inputs" column="INPUTS" />
-->
</subclass>
</subclass>
</class>
</hibernate-mapping>
Class B (Measures)
Code:
/// <summary>
/// Summary description for CMeasure
/// </summary>
namespace SocomecDBBenchMark.NHibernateDatabaseStructure
{
/// <summary>
/// Summary description for CMeasure
/// </summary>
public class CMeasure
{
private string m_sID;
private int m_iAvgEnergy;
private int m_iPhase1;
private int m_iPhase2;
private int m_iPhase3;
private int m_iVal1;
private int m_iVal2;
private int m_iVal3;
public virtual string Id
{
get
{
return m_sID;
}
set
{
m_sID = value;
}
}
public virtual int AvgEnergy
{
get
{
return m_iAvgEnergy;
}
set
{
m_iAvgEnergy = value;
}
}
public virtual int Phase1
{
get
{
return m_iPhase1;
}
set
{
m_iPhase1 = value;
}
}
public virtual int Phase2
{
get
{
return m_iPhase2;
}
set
{
m_iPhase2 = value;
}
}
public virtual int Phase3
{
get
{
return m_iPhase3;
}
set
{
m_iPhase3 = value;
}
}
public virtual int Val1
{
get
{
return m_iVal1;
}
set
{
m_iVal1 = value;
}
}
public virtual int Val2
{
get
{
return m_iVal2;
}
set
{
m_iVal2 = value;
}
}
public virtual int Val3
{
get
{
return m_iVal3;
}
set
{
m_iVal3 = value;
}
}
/// <summary>
/// Default ctor with default init values
/// </summary>
public CMeasure()
{
AvgEnergy = 10;
Phase1 = 20;
Phase2 = 30;
Phase3 = 40;
Val1 = 1;
Val2 = 2;
Val3 = 3;
}
}
}
Mapping for B (Measures)
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<!-- ********************************************************************** -->
<!-- Measures -->
<!-- ********************************************************************** -->
<class name="SocomecDBBenchMark.NHibernateDatabaseStructure.CMeasure" table="MEASURE">
<!-- A 32 hex character is our surrogate key. It's automatically
generated by NHibernate with the UUID pattern. -->
<id name="Id">
<column name="ID" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex" />
</id>
<property name="AvgEnergy" column="AVGENERGY" />
<property name="Phase1" column="PHASE1" />
<property name="Phase2" column="PHASE2" />
<property name="Phase3" column="PHASE3" />
<property name="Val1" column="VAL1" />
<property name="Val2" column="VAL2" />
<property name="Val3" column="VAL3" />
</class>
</hibernate-mapping>
Main code for adding device and measures:
Code:
public override void CreateManyLinesWithMeasuresCore()
{
if (m_Session != null)
{
ITransaction tx = m_Session.BeginTransaction();
for (int i = 0; i < 10; i++)
{
D18Device o_d18 = new D18Device(String.Format("D18 no {0}", i + 1));
ISet my_measures = new HashedSet();
for (int j = 0; j < CBaseBench.m_iMAX_MEASURES; j++)
{
CMeasure my_mesure = new CMeasure();
my_mesure.AvgEnergy = 12;
my_measures.Add(my_mesure);
}
o_d18.Measures = my_measures;
m_Session.Save(o_d18);
tx.Commit();
m_Session.Flush();
m_Session.Refresh(o_d18);
}
}
}
[/code]