I am trying to use lazy loading for a property of one of my entities
The property mapping is something like this:
<property name="Foobar" type="AnsiString" column="FOOBAR" lazy="true"/>
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
: No persister for: Castle.Proxies.FooEntityProxy"
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?
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.
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;
}
Are you sure you are using NHibernate 3? I think only this version supports scalar properties lazy loading!
update
Not sure if it can help you but try to look here:
NHibernate lazy loading property - what does build-time bytecode instrumentation mean?
or here:
NHibernate lazy properties behavior?
If you mark a property as lazy, it must be a virtual automatic property (with no body like public virtual MyType Baz { get; set; }
). If you attempt to access the underlying field value, instead of going through the property, you will circumvent the lazy loading of the property, and may get unexpected results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With