Closed
Description
Hi,
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!