Hi I am traying to generate this map using Attributes (It already works as it is):
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="Father" table="Fathers">
<id name="FatherId" type="Int32" column="FatherId">
<generator class="identity"/>
</id>
<property name="Name" column="name"/>
</class>
<class name="Mother" table="Mothers">
<id name="MotherId" type="Int32" column="MotherId">
<generator class="identity"/>
</id>
<property name="Name" column="name"/>
</class>
<class name="Son" table="Sons">
<composite-id name="Id" class="SonPK">
<key-many-to-one name="Father" class="Father" column="FatherId"/>
<key-many-to-one name="Mother" class="Mother" column="MotherId"/>
<key-property name="IdSon" column="SonId"/>
</composite-id>
<property name="Name" column="Name"/>
</class>
</hibernate-mapping>
This is where I got so far, but it is wrong:Code:
namespace IIDEA.EALIB.AplicacionPrueba.PruebaAtrubutes
{
[Class(Table = "Fathers")]
public class Father
{
private int fatherId;
[Id(0, Name = "FatherId", Column = "FatherId", TypeType = typeof(Int32))]
[Generator(1, Class = "identity")]
public virtual int FatherId
{
get { return fatherId; }
set { fatherId = value; }
}
private string name;
[Property(Name = "Name", Column = "name", TypeType = typeof(string), Length = 50)]
public virtual string Name
{
get { return name; }
set { name = value; }
}
}
[Class(Table = "Mothers")]
public class Mother
{
private int motherId;
[Id(0, Name = "MotherId", Column = "MotherId", TypeType = typeof(Int32))]
[Generator(1, Class = "identity")]
public virtual int MotherId
{
get { return motherId; }
set { motherId = value; }
}
private string name;
[Property(Name = "Name", Column = "name", TypeType = typeof(string), Length = 50)]
public virtual string Name
{
get { return name; }
set { name = value; }
}
}
[Serializable]
[Class(Name = "SonPK")]
public class SonPK
{
public SonPK()
{ }
private int idSon;
[KeyProperty(Column= "SonId")]
public virtual int IdSon
{
get { return idSon; }
set { idSon = value; }
}
private Mother mother;
[KeyManyToOne(Class="Mother",Column="MotherId")]
public virtual Mother Mother
{
get { return mother; }
set { mother = value; }
}
private Father father;
[KeyManyToOne(Class = "Father", Column = "FatherId")]
public virtual Father Father
{
get { return father; }
set { father = value; }
}
public override int GetHashCode()
{
return base.GetHashCode();
}
public override bool Equals(object obj)
{
SonPK SonPKObj = obj as SonPK;
if (SonPKObj == null)
return false;
if ((this.idSon == SonPKObj.IdSon) && (this.mother.MotherId == SonPKObj.mother.MotherId) && (this.father.FatherId == SonPKObj.father.FatherId))
{
return true;
}
return false;
}
}
[Class(Table = "Sons")]
public class Son
{
public Son()
{
id = new SonPK();
}
private SonPK id;
[CompositeId(Class= "SonPK")]
public virtual SonPK Id
{
get { return this.id; }
set { this.id = value; }
}
private string name;
[Property(Column= "name")]
public virtual string Name
{
get { return name; }
set { name = value; }
}
}
}
I found some references to some sites, but the sites are down. And I couldn't find any more information on the subject.
(I have many legacy systems)
Does any one faced this issue?
Thanks in advanced!