I am trying to map ApplicationRequest class to Request class. One Request can have multiple ApplicationRequests, but one ApplicationRequest belongs to one Request only. Below are my classes and the relevant xml mappings.
class Request
{
public virtual string Id { get; set; }
public virtual string FirstName { get; set; }
public virtual string LastName { get; set; }
public virtual string JobTitle { get; set; }
public virtual IList<ApplicationRequest> Requests { get; set; }
}
class ApplicationRequest
{
public virtual int Id { get; set; }
public virtual string RequestId { get; set; }
public virtual int AppId { get; set; }
public virtual string AppComment { get; set; }
public virtual Request Request { get; set; }
}
="1.0"="utf-8"
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="nHibernateExample" namespace="nHibernateExample">
<class name="Request" table="Requests">
<id name="Id" column="ID" generator="assigned" />
<property name="FirstName" />
<property name="LastName" />
<property name="JobTitle" />
<bag name="Requests" lazy="true">
<key column="RequestID" foreign-key="ID" />
<one-to-many class="ApplicationRequest" />
</bag>
</class>
</hibernate-mapping>
="1.0"="utf-8"
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="nHibernateExample" namespace="nHibernateExample">
<class name="ApplicationRequest" table="ApplicationRequests">
<id name="Id" column="ID" generator="native" />
<property name="RequestId" column="RequestID" />
<property name="AppId" column="AppID" />
<property name="AppComment" />
<many-to-one name="Request" class="Request">
<column name="RequestID" not-null="false" index="ID" />
</many-to-one>
</class>
</hibernate-mapping>
I am able to retrieve the Requests and its associated application requests with the following:
Request request = session.Get<Request>("R00877");
The error occurs when I try to get the ApplicationRequests with this:
List<ApplicationRequest> requests = session.Query<ApplicationRequest>().Where(x => x.RequestId == "R00877").ToList();
The inner exception is
{"Access is denied: 'nHibernateExample.Request'.":""}
and the message is
Creating a proxy instance failed
Any help regarding this would be appreciated.
What I have tried:
I have tried to change the many-to-one mapping but this error always occurs.