I need map simple table:
Code:
[ID]: integer
[FirstName]: TEXT
[LastName]: TEXT
[Father]: INTEGER
[Mother]: INTEGER
to class
Code:
class Person{
public string FirstName{get;set;}
public string LastName{get;set;}
public Person Father{get;set;}
public Person Mother{get;set;}
public IList<Person> Childrens{get;set;}
I write a workaround solution with 2 one-to-many:
Code:
class Person{
private int id;
private IList<Person> _childrens1 = new List<Person>();
private IList<Person> _childrens2 = new List<Person>();
public string FirstName{ get; set;}
public string LastName{ get; set;}
public byte Gender { get; set; }
public virtual Person Father{ get; set;}
public virtual Person Mother{ get; set;}
public virtual IList<Person> Childrens
{
get
{
List<Person> ret= new List<Person>( _childrens1 );
ret.AddRange( _childrens2 );
return ret;
}
protected set { }
}
public virtual IList<Person> Childrens1
{
get { return _childrens1; }
protected set { _childrens1 = value; }
}
public virtual IList<Person> Childrens2
{
get { return _childrens2; }
protected set { _childrens2 = value; }
}
public virtual void AddChildren(Person child)
{
if (Gender == Male)
{
if (child.Father != null)
{
child.Father._childrens1.Remove( child );
}
child.Father = this;
_childrens1.Add(child);
}
if (Gender == Female)
{
if (child.Mother != null)
{
child.Mother._childrens2.Remove(child);
}
child.Mother = this;
_childrens2.Add(child);
}
}
const byte Male = (byte)'M';
const byte Female = (byte)'F';
}
and mapping:
Code:
<class name="Person" table="Person" lazy="false">
<id name="id" unsaved-value="0" column="ID" type="System.Int32" access="field">
<generator class="identity" />
</id>
<property name="FirstName" column="FirstName"/>
<property name="LastName" column="LastName"/>
<bag name="Childrens1" fetch="select" inverse="true">
<key column="Father"/>
<one-to-many class="Person" not-found="ignore"/>
</bag>
<many-to-one name="Father" fetch="select" column="Father" class="Person" not-found="ignore"/>
<bag name="Childrens2" fetch="select" inverse="true">
<key column="Mother"/>
<one-to-many class="Person" not-found="ignore"/>
</bag>
<many-to-one name="Mother" fetch="select" column="Mother" class="Person" not-found="ignore"/>
</class>
But
"it is not cool" for my tutor.
Does a not-workaround solution exist?