Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C#
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; }
}

XML
<?xml version="1.0" encoding="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>

<?xml version="1.0" encoding="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:
C#
Request request = session.Get<Request>("R00877");
The error occurs when I try to get the ApplicationRequests with this:
C#
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.
Posted
Updated 23-Apr-19 11:07am

1 solution

Try this:

Request request = session.Get<Request>("R00877");

List<ApplicationRequest> requests = request.Select( r => r.Requests ).ToList();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900