a single table is correct. but the ParentDistrictID has to be nullable:
Code:
T_District
DistrictID [ Identity ]
DistrictName [ varchar(50) ]
ParentDistrictID [ Nullable ]
Your class might look like:
Code:
public class District() {
private int id;
private string name;
private District parentDistrict;
privte IList childrenDistricts;
... properties ...
}
Class mapping:
Code:
<class name=District lazy=true>
<id name="id" ... >
generator class="identity" />
</id>
<property name="Name" column="DistrictName" type=string not-null=true />
<many-to-one name="ParentDistrict" class="district" column="ParentDistrictID" />
</class>
i definitely recommend marking the association as lazy otherwise you might load an entire object graph that you don't want.
then in your DAO you can get all children like so:
Code:
return session.CreateCriteria(typeofDistrict))
.Add(Expression.Eq("ParentDistrict", parentDistrict))
.AddOrder(Order.Asc("Name"))
.List();
wheee! :)