title: How to activate the second level cache on a lazy loaded property with own user type?
body: <p><strong>Preface</strong>:<br>
  In my application, I store raw WAV data in the database as <code>byte[]</code>. In my domain model there is a class <code>PcmAudioStream</code> that represents that raw WAV data. I created an implementation of NHibernate's <code>IUserType</code> to convert between my class and <code>byte[]</code>.<br>
  There are several classes that use the <code>PcmAudioStream</code> class, all of which are mapped to database tables. To avoid always loading all WAV data when retrieving a row from such a table, I created an implementation of Fluent NHibernate's <code>IUserTypeConvention</code> that specifies that those properties should always be lazy loaded.<br>
  All of this works like a charm.</p>
  
  <p><strong>Question:</strong><br>
  Because the content of these <code>PcmAudioStream</code>s rarely ever changes, I want to put retrieved instances in the second level cache. Now, I know how to activate the second level cache for a complete class, but how do I achieve this only for a lazy loaded property?</p>
  
  <hr>
  
  <p>The relevant part of my domain model looks like this:</p>
  
  <pre><code>public class User : Entity
  {
      public virtual string FirstName { get; set; }
      public virtual string LastName { get; set; }
      public virtual PcmAudioStream FullNameRecording { get; set; }
      // ...
  }
  </code></pre>
  
  <p>The mapping is simple (note: that is not my mapping, I am using a convention, but it is equivalent):</p>
  
  <pre><code>public class UserMap : ClassMap&lt;User&gt;
  {
      public UserMap()
      {
          Id(x =&gt; x.Id);
          Map(x =&gt; x.FirstName);
          Map(x =&gt; x.LastName);
          Map(x =&gt; x.FullNameRecording).CustomType&lt;PcmAudioStreamAsByteArray&gt;();
      }
  }
  </code></pre>