Nhibernate创建代理实例失败 [英] Nhibernate creating a proxy instance failed

查看:101
本文介绍了Nhibernate创建代理实例失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将ApplicationRequest类映射到Request类。一个请求可以有多个ApplicationRequests,但一个ApplicationRequest只属于一个Request。下面是我的类和相关的xml映射。



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




<?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:

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

当我尝试使用以下内容获取ApplicationRequests时出现错误:

The error occurs when I try to get the ApplicationRequests with this:

List<ApplicationRequest> requests = session.Query<ApplicationRequest>().Where(x => x.RequestId == "R00877").ToList();

内部异常是

{"Access is denied: 'nHibernateExample.Request'.":""}

并且消息是

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.

推荐答案

试试这个:



Try this:

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

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


这篇关于Nhibernate创建代理实例失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆