没有持留为:Castle.Proxies<的entityName>代理和懒惰="真"。在NHibernate的?懒惰、LT、Castle、Proxies

2023-09-04 23:59:24 作者:立白歌手我是洗衣液

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

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