title: Usage of NHibernate Interceptor(s) on Projections
body: <p>I have this situation:</p>
  
  <p>I'm using Nhibernate to map an Entity '<strong>User</strong>' that is mapped on a large table in Sql, for perfomance reasons I've created a lightweight entity '<strong>LightweightUser</strong>' that has only a small set of properties and is <strong>NOT</strong> mapped in a hbm file or whatever, I'm using the <strong>Nhibernate Projection</strong> technique to wire the '<strong>LightweightUser</strong>' entity. Both entities are deriving from a simple class 'Entity' that contains an Id property.</p>
  
  <p>The above implementations works fine, sql query is smaller == faster.</p>
  
  <p>But in my Nhibernate SessionFactory I have also injected a <strong>Nhibernate Intercerptor</strong>. 
  The <strong>OnLoad</strong> method of the Interceptor is called when I'm getting a '<strong>User</strong>' entity from the NHibernate Dao, but when I get the '<strong>LightweightUser</strong>' entity from the NHibernate Dao the Interceptor is <strong>not triggered</strong> (OnLoad method).</p>
  
  <p>This is probably related to the fact that NHibernate SessionFactory has no knowledge of my 'LightweightUser' entity. Is there a way to inform the Sessionfactory/ Interceptor of the existence of my 'Lightweight' entity? Or is there some other technique to wire Projections to an Interceptor?  And yes I can also duplicate the the 'hbm' file for my Lightweight entity, but that seems like bad practice.</p>
  
  <pre><code>    [TestFixture]
      public class InterceptorTest : NhibernateSessionHelper
      {
      [Test]
      public void GetEntiy()
      {
          //ok trigger OnLoad in the Interceptor
          var user = GetSession().Get&lt;User&gt;(1);
          Assert.IsNotNull(user);
      }
  
      [Test]
      public void GetProjection()
      {
          var crit = GetSession().CreateCriteria&lt;User&gt;();
          crit.Add(Restrictions.Eq("Id", 5));
          crit.SetProjection(Projections.ProjectionList()
                                        .Add(Projections.Property("Id"), "Id")
                                        .Add(Projections.Property("Username"), "UserName"));
  
          crit.SetResultTransformer(Transformers.AliasToBean(typeof(LightweightUser)));
  
          //does not trigger the Interceptor
          var result = crit.List&lt;LightweightUser&gt;();
  
          Assert.IsNotNull(result.First());
  
      }
  } 
  
  
      //Wire the Sessionfactory with Interceptor
      private static ISessionFactory CreateSessionFactory()
      {
          return new Configuration()
          .CurrentSessionContext&lt;ThreadStaticSessionContext&gt;()
          .SetInterceptor(new MyInterceptor())
              .Configure().BuildSessionFactory();
      }
  
  
   public class MyInterceptor: IInterceptor
  {
      public override bool OnLoad(object entity, object id, object[] state, string[] propertyNames, NHibernate.Type.IType[] types)
      {
          //do stuff
  
          var s = entity;
          return base.OnLoad(entity, id, state, propertyNames, types);
      }
  </code></pre>
  
  <p>Thanks in advance</p>