You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've encountered an issue where accessing the Id property of a Proxy via an interface causes the Entity to be loaded.
public interface IEntity
{
int Id { get; }
}
public class Entity : IEntity
{
public virtual int EntityId { get; set; }
int IEntity.Id => EntityId;
}
public void Test(ISessionFactory sessionFactory, int id)
{
Entity entity;
IEntity iEntity;
using (ISession session = sessionFactory.OpenSession())
{
var x = session.Load<Entity>(id);
entity = x;
iEntity = x;
}
Assert.Equal(id, entity.EntityId); // OK
Assert.Equal(id, iEntity.Id); // LazyInitializationException
}
I saw several threads that looked related, but unfortunately they dealt with more complicated situations (subclasses, etc.) and I'm not well-versed in NHibernate's internals. Most seem to indicate issues had been fixed, though. My issue is showing up on 5.2.5.
Is there something I am not understanding, or a workaround available?
Thanks!
The text was updated successfully, but these errors were encountered:
Your case will not be fixed. You should remove the explicit implementation and only use the implicit ones. Then it should work with NHibernate 5.3, but it may depend on how we fix #2085, if we fix it.
With an explicit implementation of an interface, if the entity is mapped as the concrete class, there are no way NHibernate could tell if the Id property from the interface will actually match the Id from the mapped concrete class. So instead of doing some wild guess, it must trigger the proxy loading to simply call it and see what it yields.
Hi,
I've encountered an issue where accessing the Id property of a Proxy via an interface causes the Entity to be loaded.
I saw several threads that looked related, but unfortunately they dealt with more complicated situations (subclasses, etc.) and I'm not well-versed in NHibernate's internals. Most seem to indicate issues had been fixed, though. My issue is showing up on 5.2.5.
Is there something I am not understanding, or a workaround available?
Thanks!
The text was updated successfully, but these errors were encountered: