没有持留为:Castle.Proxies<的entityName>代理和懒惰="真"。在NHibernate的? [英] No persister for: Castle.Proxies.<EntityName>Proxy and lazy="true" in NHibernate?

查看:307
本文介绍了没有持留为:Castle.Proxies<的entityName>代理和懒惰="真"。在NHibernate的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用延迟加载为我的实体之一的属性

I am trying to use lazy loading for a property of one of my entities

属性映射是这样的:

<property name="Foobar" type="AnsiString" column="FOOBAR" lazy="true"/>

当我特林保存该实体的一个实例,但是(使用LINQ),它抛出具有以下内部异常的DatabaseQueryException:

However when I am tring to save an instance of this entities (using Linq), it throws a DatabaseQueryException with the following inner exception:

NHibernate.MappingException :不持留​​为:Castle.Proxies.FooEntityProxy

NHibernate.MappingException: No persister for: Castle.Proxies.FooEntityProxy"

而当我删除懒惰=真正的项目,除没有得到再抛出。什么是使用问题为lazy =true和如何解决这一问题?

And when I remove the lazy="true" item, the exception doesn't get thrown anymore. What is the problem with using lazy="true" and how to fix this?

推荐答案

我知道这是一个迟到的答案,但我有同样的问题前面。我使用的是自定义拦截器来创建代理,等我发现的问题是,我没有覆盖的GetEntityName的方法。在GetEntityName方法中的代理分析,并返回正确的类名并获得成功。

I know this is a late answer, but I had this same problem earlier. I was using a custom interceptor to create the proxies, and so I found that the issue was that I hadn't overridden the "GetEntityName" method. Analyzing the proxy within the GetEntityName method, and returning the proper class name did the trick.

在我的情况,我有一个简单的扩展方法unproxy我的对象,被称为UnProxy,所以我的整个实施这一方法是这样的:

In my case, I had a simple extension method to unproxy my objects, called "UnProxy", so my whole implementation of this method looked like this:

public override string GetEntityName(object entity)
{
    if (entity == null)
        return base.GetEntityName(entity);
    return entity.UnProxy().GetType().FullName;
}

这篇关于没有持留为:Castle.Proxies&LT;的entityName&GT;代理和懒惰=&QUOT;真&QUOT;。在NHibernate的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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