非法访问加载集合

时间:2015-07-23 13:08:25

标签: c# nhibernate fluent-nhibernate

我知道有很多答案。但是我没有失去想要的东西。我已经尝试了很多,但没有找到遗漏的东西。获得'illegal access to loading collection '

即使任何建议都会被抨击

nhibernate .hbm

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping namespace="EMSModels" assembly="EMSModels" xmlns="urn:nhibernate-mapping-2.2">
  <class name="Reimbursement" table="Reimbursement">
    <id name="ID" column="ReimbursementID" type="int">
      <generator class="native" />
    </id>
    <property name="EmployeeID" type="int" />
    <property name="SubmissionDate" type="DateTime" />
    <property name="Description" type="string" length="500" />
     <property name="IsActive" type="bool" />
    <property name="IsDeleted" type="bool" />
    <many-to-one name="Employee" class="Employee" column="EmployeeID" insert="false" update="false"/>
    <bag name="ReimbursementDetails"  cascade="all" inverse="true">
      <key column="ReimbursementID"></key>
      <one-to-many class="ReimbursementDetails"/>
    </bag>
  </class>
</hibernate-mapping>

模型

public class Reimbursement
{
    public virtual int ID { get; set; }
    public virtual int EmployeeID { get; set; }
    public virtual DateTime SubmissionDate { get; set; }
    public virtual string Description { get; set; }
    public virtual bool IsActive { get; set; }
    public virtual bool IsDeleted { get; set; }
    public virtual Employee Employee { get; set; }
    // public virtual ReimbursementDetails ReimbursementDetails { get; set; }
    public virtual IList<ReimbursementDetails> ReimbursementDetails { get; set; }

    public virtual string Custom_SubmissionDate
    {
        get
        {
            DateTime date = SubmissionDate;
            return date.ToString("dd-MMM-yyyy");
        }
    }
}

1 个答案:

答案 0 :(得分:0)

您的实体中有一个延迟加载的集合,并且在您想要加载集合的那一刻,您的NHibernate会话已关闭。