日期:2014-05-19  浏览次数:20827 次

NHibernate,多对一查询问题
假设有两张表,分别是部门表和职员表。其中职员表中的部门ID与部门表中的ID是多对一关系。现在要根据部ID查找所有的职员信息,该怎么写?

------解决方案--------------------
好像只要弄下配置的XML和实体类就行了吧!!!

都参考下NHibernate的文档!!!
------解决方案--------------------
如果表A与表B是一对多:
A的实体类:
private IList <B> _b;
public virtual IList <B> b
{
get { return _b; }
set { _b = value; }
}
A的映射文件里:
<bag name= "b " table= "Table_B " lazy= "true ">
<key column= "A_ID "/>
<one-to-many class= "EntityB " not-found= "ignore " />
</bag>
B的实体类:
private A _a;
public virtual A a
{
get { return _a; }
set { _a = value; }
}
B的映射文件里:
<many-to-one name= "a " class= "EntityA " not-found= "exception " lazy= "proxy " column= "B_ID " />