title: How to map a view without an identity column in NHibernate?
body: <p>I have a view that I am going to only read from (no writes). This view does not have any unique key (not event composite). </p>
  
  <p>So how can I map this view in NHibernate without touching the view? I do not want to add a new column to the view to generate a unique identity for me. Is there a way to map this view and generate the identity column on the NHibernate side? </p>
  
  <p>I can generate a GUID in my entity class like: </p>
  
  <pre><code>public class MyViewClass
  {
      private Guid _id = new Guid();
      public virtual Guid Id { get { return _id; } set { _id = value; } }
  }
  </code></pre>
  
  <p>But how can I make the mapping work? The following code does not work:</p>
  
  <pre><code>public class MyViewClass: ClassMapping&lt;MyViewClass&gt;
  {
      public MyViewClass()
      {
          Mutable(false);
          Id(x =&gt; x.Id, m =&gt; m.Generator(Generators.Guid));
      }
  
  } 
  </code></pre>
  
  <p>It expects to have the Id column in view and throws: </p>
  
  <pre><code>System.Data.SqlClient.SqlException: Invalid column name 'Id'.
  </code></pre>
  
  <p>BTW, I am using NHibernate 3.2 and mapping by code.</p>