Hello,
Maybe I'll find some help in here.
My Problem:
I want to map the objects created by NHibernate to a DataGridView. The Problem is not all objects do look the same. My idea was that the objects now implement an Interface (IVisualizableTeststep) that's implements getters and setters, but Hibernate doesn't let me implement the interface.
Here are my classes:
Teststep Superclass
Code:
public abstract class Teststep
{
public virtual String Name { get; set; }
public virtual String Keyword { get; set; }
public virtual Decimal Id { get; set; }
public virtual Decimal IsVirtual { get; set; }
public virtual Decimal Position { get; set; }
public virtual Module Parent { get; set; }
public Teststep()
{
IsVirtual = 0;
}
}
and i have several child classes which look like the following two:
MeasureVoltage child classCode:
public class MeasureTeststep : Teststep
{
public virtual double UpperLimit { get; set; }
public virtual double LowerLimit { get; set; }
public virtual String MeasurePosition { get; set; }
public virtual String Currency { get; set; }
public MeasureTeststep()
: base()
{
}
}
public class MeasureVoltage : MeasureTeststep
{
public MeasureVoltage()
: base()
{
}
public MeasureVoltage(double lowerLimit, double upperLimit, String measurePosition, VoltageCurrencies currency)
: base()
{
LowerLimit = lowerLimit;
UpperLimit = upperLimit;
MeasurePosition = measurePosition;
switch (currency)
{
case VoltageCurrencies.V: Currency = "V";
break;
case VoltageCurrencies.mV: Currency = "mV";
break;
}
}
}
SendCommand child classCode:
public class SendCommand : Teststep
{
public virtual String Command { get; set; }
public virtual String Answer { get; set; }
public SendCommand()
{
Command = "";
Answer = "";
}
}
The mapping file for this classes:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="ETToolV2" namespace="Continental.ETTool">
<class abstract="true" name="Teststep" table="ET_TESTSTEP">
<id name="Id" column="ID_TESTSTEP" type="Decimal">
<generator class="sequence">
<param name="ET_TESTSTEP_SEQ"/>
</generator>
</id>
<discriminator column="TESTSTEP_TYPE" type="String" />
<property name="Name" type="String" column="DESCRIPTION" />
<property name="Keyword" type="String" column="KEYWORD" />
<property name="IsVirtual" type="Decimal" column="IS_VIRTUAL" />
<property name="Position" type="Decimal" column="POSITION" not-null="true"/>
<many-to-one name="Parent" not-null="true" column="ID_MODULE" />
<subclass name="SendCommand" discriminator-value="0">
<property name="Command" type="String" column="PARAMETER0" />
<property name="Answer" type="String" column="PARAMETER1" />
</subclass>
<subclass name="MeasureTeststep" abstract="true">
<property name="LowerLimit" type="Double" column="PARAMETER0" />
<property name="UpperLimit" type="Double" column="PARAMETER1" />
<property name="MeasurePosition" type="String" column="PARAMETER2" />
<property name="Currency" type="String" column="PARAMETER3" />
<subclass name="MeasureVoltage" extends="MeasureTeststep" discriminator-value="10"/>
</subclass>
</class>
</hibernate-mapping>
Hope I haven't forgot anything, but this works fine.
Now if I try to do something like:
Code:
public interface IVisualizableTeststep
{
String Name { get; set; }
String Keyword { get; set; }
String Parameter0 { get; set; }
String Parameter1 { get; set; }
}
}
Now I try to implement the interface:
Code:
public class SendCommand : Teststep, IVisualizableTeststep
{
public virtual String Command { get; set; }
public virtual String Answer { get; set; }
public virtual Parameter0
{
get{return Command;}
set{Command = value;}
}
public virtual Parameter1
{
get{return Answer;}
set{Answer = value;}
}
public SendCommand()
{
Command = "";
Answer = "";
}
}
Now I get an Error from Hibernate telling me that set_Parameter0() should be virtual...
anybody got an idea how I could solve this? I'm relatively new to NHibernate. If anybody got another idea how I could map the objects to a DataGridView please let me know.
Thanks for your help,
Florian Fanderl