Hi. I have a simple class hierarchy with 3 classes which are the following:
Code:
public class Device
{
private int id;
private string macAddress;
}
public class Logger : Device
{
private int reportinterval;
}
public class Sensor : Device
{
private int sampleRate;
private int measuringTime;
}
The Device class is just an "interface", it is just the parent class of the other two classes to consist the common fields. I will use it in a gridview for example but when I select a row I wanna get the Logger or Sensor object, so actually there won't be any Device object in my application.
I checked the NHibertnate's documentation and I chose the one-table-per-hierarchy implementation but my tutor said it is not good because it may not work and I couldn't convince him it will. So I implemented a following relational database:
Code:
CREATE TABLE `device` (
`Id` int(11) NOT NULL auto_increment,
`MacAddress` varchar(4) NOT NULL,
PRIMARY KEY (`Id`),
UNIQUE KEY `U_Device` (`MacAddress`)
) ENGINE=InnoDB;
CREATE TABLE `logger` (
`Id` int(11) NOT NULL auto_increment,
`ReportInterval` int(11) default NULL,
`DeviceId` int(11) default NULL,
PRIMARY KEY (`Id`),
KEY `FK_Logger_Device` (`DeviceId`)
) ENGINE=InnoDB;
CREATE TABLE `sensor` (
`Id` int(11) NOT NULL auto_increment,
`SampleRate` int(11) default NULL,
`MeasuringTime` int(11) default NULL,
`DeviceId` int(11) default NULL,
PRIMARY KEY (`Id`),
KEY `FK_Sensor_Device` (`DeviceId`)
) ENGINE=InnoDB;
ALTER TABLE `logger`
ADD FOREIGN KEY (`DeviceId`) REFERENCES `device` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `sensor`
ADD FOREIGN KEY (`DeviceId`) REFERENCES `device` (`Id`) ON DELETE CASCADE ON UPDATE CASCADE;
My question is how to map this database into my object model, bacause I couldn't find any example yet. Could anyone help me? Thanx a lot.