Hi,
Did you make it work?
I am doing some test with attributes and composite-id and i havenĀ“t been able to make it work, because I can't find a documentation of how to implement it.
1. I don't know what attribute to use in my class containing the Primary Key.[class] or [component]?
2. Which attribute should I use when I make a reference to the Primary class [CompositeElement]?
This is what I have, but it is not working:
Code:
[Serializable]
[Class(Name = "Id")]
public class SonPK
{
public SonPK()
{ }
[NHibernate.Mapping.Attributes.CompositeId(1)]
[KeyManyToOne(2, Name = "Mother", Class = "Mother", Column = "MotherId")]
[KeyManyToOne(3, Name = "Father", Class = "Father", Column = "FatherId")]
[KeyProperty(4, Name = "IdSon", Column = "SonId")]
private int idSon;
public virtual int IdSon
{
get { return idSon; }
set { idSon = value; }
}
private Mother mother;
public virtual Mother Mother
{
get { return mother; }
set { mother = value; }
}
private Father father;
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 SonHer
{
public SonHer()
{
id = new SonPK();
}
private SonPK id;
[NHibernate.Mapping.Attributes.CompositeElement(ClassType = typeof(SonPK))]
public virtual SonPK Id
{
get { return this.id; }
set { this.id = value; }
}
}
Thanks