Hi there!
I have to work on a given table structure and use NHibernate with mapping attributes. I'm trying to create a mapping for a one-to-one relation.
The table situation is like that:
parent table's columns:
Code:
id (guid)
is_deleted (boolean)
{some more values}
childA table's columns:
(having a one-to-one relation to the parent)Code:
id (guid)
parent_id (guid)
{some values}
childB table's columns:
(having an ordered many-to-one relation to the parent)Code:
id (guid)
parent_id (guid)
order (int)
{some values}
I know/read that the one-to-one relation could even be created as a many-to-one, but nevertheless I'm stuck with the attributes/the mapping on that one with the given table structure.
Hibernate version: 1.2.0.2002
Mapping attributes: that's the questionCode:
[Serializable]
[Class(Table = "parent", Lazy = false)]
public class ParentClass
{
#region --- private ---
private Guid m_Id;
private bool m_IsDeleted;
private IList<ChildBClass> m_ChildBList;
private ChildAClass m_ChildA;
#endregion --- private ---
public ParentClass()
{
m_Id = Guid.Empty;
m_IsDeleted = false;
m_ChildBList = new List<ChildBClass>();
m_ChildA = new ChildAClass();
}
[Id(0, Name = "Id", Column = "id", Type = "Guid")]
[Generator(1, Class = "guid")]
public virtual Guid Id
{
get { return (m_Id); }
set { m_Id = value; }
}
[Property(Column = "is_deleted", Type = "Boolean")]
public virtual bool IsDeleted
{
get { return (m_IsDeleted); }
set { m_IsDeleted = value; }
}
[List(0, Table = "childB", Lazy = false, Cascade = CascadeStyle.AllDeleteOrphan)]
[Key(1, Column = "parent_id")]
[Index(2, Column = "order", Type = "Int32")]
[OneToMany(3, Class = "ChildBClass, hbm_assembly")]
public virtual IList<ChildBClass> ChildBList
{
get { return (m_ChildBList); }
set { m_ChildB = value; }
}
[OneToOne(Class = "ChildAClass, hbm_assembly", ???????]
public virtual ChildAClass ChildA
{
get { return (m_ChildA); }
set { m_ChildA = value; }
}
}
[b]Any help highly appreciated![\b]