NHibernate问题,集合列的读取。
目前有两个表,职员表和部门表。其中职员表中的部门ID是集合列,如何把当前职员的部门ID显示出来呢。
我的代码如下。
映射文件及XML文件:
职员表XML文件
<?xml version= "1.0 " encoding= "utf-8 " ?>
<hibernate-mapping xmlns= "urn:nhibernate-mapping-2.2 " namespace= "Domain.Admin " assembly= "Domain ">
<class name= "Staff " table= "PB_STAFF " proxy= "Staff ">
<cache usage= "read-write " />
<id name= "LoginId " column= "PB_LOGIN_ID " type= "String " length= "20 ">
<generator class= "assigned "/>
</id>
<property name= "Password " column= "PB_PASSWORD " type= "String " not-null= "true " length= "40 " />
<property name= "Code " column= "PB_CODE " type= "String " length= "40 " />
<property name= "Name " column= "PB_NAME " type= "String " not-null= "true " length= "40 " />
<property name= "Sex " column= "PB_SEX " type= "Nullables.NHibernate.NullableInt32Type, Nullables.NHibernate " />
<property name= "Disabled " column= "PB_DISABLED " type= "Int32 " not-null= "true " />
<property name= "OrderId " column= "PB_ORDER_ID " type= "Int32 " not-null= "true " />
<many-to-one name= "Department " column= "PB_DEPARTMENT_ID " class= "Department " />
<set name= "Roles " table= "PB_STAFF_ROLE " lazy= "true ">
<cache usage= "read-write " />
<key column= "PB_LOGIN_ID " />
<many-to-many class= "Role " column= "PB_ROLE_ID " outer-join= "false " />
</set>
<set name= "ModuleRightsGrant " table= "PB_STAFF_MODULE_RIGHT_GRANT " lazy= "true ">
<cache usage= "read-write " />
<key column= "PB_LOGIN_ID " />
<many-to-many class= "ModuleRight " column= "PB_RIGHT_ID " outer-join= "false " />
</set>
<set name= "ModuleRightsDeny " table= "PB_STAFF_MODULE_RIGHT_DENY " lazy= "true ">
<cache usage= "read-write " />
<key column= "PB_LOGIN_ID " />
<many-to-many class= "ModuleRight " column= "PB_RIGHT_ID " outer-join= "false " />
</set>
</class>
</hibernate-mapping>
职员映射类
namespace Domain .Admin
{
/// <summary>
///职员。
/// </summary>
public class Staff
{
private string _login_id;
private string _password;
private string _code;
private string _name;
private NullableInt32 _sex;
private int _disabled;
private int _order_id;
private Department _department;
private ISet _roles;
private ISet _module_rights_grant;
private ISet _module_rights_deny;
#region 属性
/// <summary>
/// 登录ID。
/// </summary>
public virtual string LoginId
{
get { return _login_id; }
set { _login_id = value; }
}
/// <summary>
/// 登录密码。
/// </summary>
public virtual string Password
{
get { return _password; }
set { _password = value; }
}
/// <summary>
/// 编号。
/// </summary>
public virtual string Code
{
get { return _code; }
set { _code = value; }
}
/// <summary>
/// 姓名。
/// </summary>
public virtual string Name
{
get { return _name; }
set { _name = value; }
}
/// <summary>
/// 性别。
/// </summary>
public virtual NullableInt32 Sex
{
get { return _sex; }
set { _sex = value; }
}
/// <summary>
/// 已禁用。
/// </summary>
public virtual int Disabled
{
get { return _disabled; }
set { _disabled = value; }
}
/// <summary>
/// 排序ID。
/// </summary>
public virtual int OrderId
{
get { return _order_id; }
set { _order_id = value; }
}
/// <summary>
/// 所属部门。
/// </summary>
public virtual Department Department
{
get { return _department; }
set { _department = value; }
}
/// <summary>
/// 角色列表。
/// </summary>
public virtual ISet Roles
{
get { return _roles; }
set { _roles = value; }
}
/// <summary>
/// 对当前职员进行了肯定授权的模块权限。
/// </summary>
public virtual ISet ModuleRightsGrant
{
get { return _module_rights_grant; }
set { _module_rights_grant = value; }
}
/// <summary>
/// 对当前职员进行了否定授权的模块权限。
/// </summary>
public virtual ISet ModuleRightsDeny
{
get { return _module_rights_deny; }
set { _module_rights_deny = value; }
}
#endregion
#region 构造函数
public Staff()
{
_login_id = String.Empty;
_password = String.Empty;
_code = String.Empty;
_name = String.Empty;
_sex = null;
_disabled = 0;
_order_id = 0;
_department = null;
_roles = new HashedSet();
_module_rights_grant = new HashedSet();
_module_rights_deny = new HashedSet();
}
#endregion
}
}
部门XML
<?xml version= "1.0 " encoding= "utf-8 " ?>
<hibernate-mapping xmlns= "urn:nhibernate-mapping-2.2 " namespace= "Domain.Admin " assembly= "Domain ">
<class name= "Department " table= "PB_DEPARTMENT " proxy= "Department ">
<cache usage= "read-write " />
<id name= "Id " column= "PB_ID " type= "String " length= "15 ">
<generator class= "assigned " />
</id>
<property name= "Name " column= "PB_NAME " type= "String " not-null= "true " length= "40 " />
<property name= "OrderId " column= "PB_ORDER_ID " type= "Int32 " not-null= "true " />
<many-to-one name= "ParentDepartment " column= "PB_PARENT_ID " class= "Department " />
<bag name= "SubDepartments " inverse= "true " order-by= "PB_PARENT_ID " lazy= "true ">
<cache usage= "read-write " />
<key column= "PB_PARENT_ID " />
<one-to-many class= "Department " />
</bag>
<bag name= "Staff " inverse= "true " order-by= "PB_DISABLED, PB_ORDER_ID " lazy= "true ">
<cache usage= "read-write " />
<key column= "PB_DEPARTMENT_ID " />
<one-to-many class= "Staff " />
</bag>
</class>
</hibernate-mapping>
部门映射类文件
using System;
using System.Collections;
namespace Domain .Admin
{
/// <summary>
///部门。
/// </summary>
public class Department
{
private string _id;
private string _name;
private int _order_id;
private Department _parent_department;
private IList _staff;
private IList _sub_departments;
#region 属性
/// <summary>
/// ID。
/// </summary>
public virtual string Id
{
get { return _id; }
set{ _id = value; }
}
/// <summary>
/// 名称。
/// </summary>
public virtual string Name
{
get { return _name; }
set{ _name = value; }
}
/// <summary>
/// 排序ID。
/// </summary>
public virtual int OrderId
{
get { return _order_id; }
set { _order_id = value; }
}
/// <summary>
/// 上级部门。
/// </summary>
public virtual Department ParentDepartment
{
get { return _parent_department; }
set { _parent_department = value; }
}
/// <summary>
/// 职员列表。
/// </summary>
public virtual IList Staff
{
get { return _staff; }
set { _staff = value; }
}
/// <summary>
/// 子部门列表。
/// </summary>
public virtual IList SubDepartments
{
get { return _sub_departments; }
set { _sub_departments = value; }
}
#endregion
#region 构造函数
public Department()
{
_id = String.Empty;
_name = String.Empty;
_phone = String.Empty;
_ext_number = String.Empty;
_fax = String.Empty;
_remark = String.Empty;
_order_id = 0;
_parent_department = null;
_staff = new ArrayList();
_sub_departments = new ArrayList();
}
#endregion
}
}
[解决办法]
不懂呀,帮顶
[解决办法]
继续
[解决办法]
帮顶
[解决办法]
自己解决了啊,呵呵。
那就来接分吧。
[解决办法]
接分,呵呵
[解决办法]
Staff.DepartMent.ID
[解决办法]
顺路
[解决办法]
马甲?
[解决办法]
JF
偶现在总是说找不到程序集