I did this:
Code:
using System;
using System.Collections.Generic;
using System.Text;
namespace AplicacionPrueba.PruebaAtrubutes
{
public interface IManufacturer
{
string Name { get; set; }
}
[NHibernate.Mapping.Attributes.Component(ClassType=typeof(IIDEA.EALIB.AplicacionPrueba.PruebaAtrubutes.Manufacturer) )]
public class Manufacturer : IManufacturer
{
private string name;
[NHibernate.Mapping.Attributes.Property( Column = "manufacturername")]
public string Name
{
get { return name; }
set { name = value; }
}
}
public interface IVehicle
{
int VehicleId { get; set; }
IManufacturer ManufacturerName { get; set; }
string OwnerName { get; set; }
decimal Weigth { get; set; }
}
[NHibernate.Mapping.Attributes.Class(Table = "vehicles")]
public abstract class Vehicle : IVehicle
{
private int vehicleId;
private IManufacturer manufacturerName;
private string person;
private decimal weigth;
[NHibernate.Mapping.Attributes.Id(0, Name = "VehicleId", Column = "vehicleId", TypeType = typeof(Int32))]
[NHibernate.Mapping.Attributes.Generator(1, Class = "identity")]
public int VehicleId
{
get { return vehicleId; }
set { vehicleId = value; }
}
[NHibernate.Mapping.Attributes.ComponentProperty(ComponentType = typeof(IIDEA.EALIB.AplicacionPrueba.PruebaAtrubutes.Manufacturer))]
public IManufacturer ManufacturerName
{
get { return manufacturerName; }
set { manufacturerName = value; }
}
[NHibernate.Mapping.Attributes.Property(Name="OwnerName", Column= "ownername")]
public string OwnerName
{
get { return person; }
set { person = value; }
}
[NHibernate.Mapping.Attributes.Property(Name="Weigth", Column= "weigth")]
public decimal Weigth
{
get { return weigth; }
set { weigth = value; }
}
}
public interface IBicycle : IVehicle
{
string WheelSize { get; set; }
}
[NHibernate.Mapping.Attributes.JoinedSubclass(ExtendsType = typeof(Vehicle), Table = "bicycles")]
public class Bicycle : Vehicle, IBicycle
{
private string wheelSize;
[NHibernate.Mapping.Attributes.Key(0,Column="VehicleId")]
[NHibernate.Mapping.Attributes.Property(1,Name="WheelSize",Column="wheelsize")]
public string WheelSize
{
get { return wheelSize; }
set { wheelSize = value; }
}
}
public interface IAutomotive : IVehicle
{
int CylinderCount { get;set;}
int SeatCount { get;set;}
string Description { get;set;}
}
[NHibernate.Mapping.Attributes.JoinedSubclass(ExtendsType = typeof(Vehicle), Table = "automotives")]
public class Automotive : Vehicle, IAutomotive
{
private int cylinderCount;
private int seatCount;
private string description;
[NHibernate.Mapping.Attributes.Key(0, Column = "VehicleId")]
[NHibernate.Mapping.Attributes.Property(1,Name="CylinderCount",Column="cylinderCount")]
public int CylinderCount
{
get { return cylinderCount; }
set { cylinderCount = value; }
}
[NHibernate.Mapping.Attributes.Property(Name="SeatCount",Column="seatCount")]
public int SeatCount
{
get { return seatCount; }
set { seatCount = value; }
}
[NHibernate.Mapping.Attributes.Property(Name="Description",Column="description")]
public string Description
{
get { return description; }
set { description = value; }
}
}
}
To generate this map:Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="Northwind.Domain.Entities" assembly="Northwind.Domain">
<class name="Vehicle" table="vehicles">
<id name="VehicleId" type="Int32" column="vehicleId">
<generator class="identity"/>
</id>
<property name="OwnerName" column="ownername"/>
<property name="Weigth" column="weigth"/>
<component name ="Manufacturer" class="Manufacturer">
<property name="Name" column="manufacturername"/>
</component>
<!--Definición de una bicicleta.-->
<joined-subclass name="Bicycle" table="bicycles">
<key column="VehicleId"/>
<property name="WheelSize" column="wheelsize"/>
</joined-subclass>
<!--Definición de un Aotomóvil-->
<joined-subclass name="Automotive" table="automotives">
<key column="VehicleId"/>
<property name="CylinderCount" column="cylinderCount"/>
<property name="SeatCount" column="seatCount"/>
<property name="Description" column="description"/>
</joined-subclass>
</class>
<sql-query name="ObtenerVehiculos">
<return alias="listaTodosVehiculos" class="Vehicle"/>
SELECT * FROM vehicles
</sql-query>
</hibernate-mapping>