title: Property which should be a readonly db-field (Fluent NHibernate Automapping)
body: <p>Im using the Fluent NHibernate together with the automapping functionality. Now im lookin' for something like a configuration, setting, custom attribute - whatever - to declare an entity property as "ReadOnlyFromDb"</p>
  
  <p>In the MsSql database im using a computed column in one of my tables where a value is calculated depending on some other values of the specific data row. Now I have declared this column in the entity class as </p>
  
  <pre><code>public virtual int STATUS { get; private set; }
  </code></pre>
  
  <p>On getting the specific data of the table everything works fine. The property <code>STATUS</code> is filled correct with the specific value in the datatable.</p>
  
  <p>The problem occures when i try to <code>SaveUpdate()</code> the specific object.
  I always get the exception</p>
  
  <pre><code>A computed column cannot be the target of an INSERT or UPDATE statement
  </code></pre>
  
  <p>Which is correct for my understanding - and its how it was supposed to be ;)!</p>
  
  <p>Basically im looking for a configuration, setting, custom attribute - whatever - to say</p>
  
  <blockquote>
    <p>Hey Fluent NHibernate - get the specific property <code>propertyName</code> but do not insert / update the property <code>propertyName</code></p>
  </blockquote>
  
  <p>Is there something like that? Or does a workaround exists for this case?
  I've searched the fluent nhibernate wiki but have not found a smilliar case.</p>
  
  <p>I hope that someone has already faced and solved this problem!</p>
  
  <p>Here is the code snippet how I create the session (maybe it helps):</p>
  
  <pre><code>    public static ISessionFactory GetNHibernateSession()
      {
          if (nhibernateSession != null)
              return nhibernateSession;
  
          if (ConfigurationManager.AppSettings[msSqlConnectionString] == null || ConfigurationManager.AppSettings[msSqlConnectionString] == String.Empty)
              throw new NullReferenceException(String.Format("AppSetting '{0}' must not be null!", msSqlConnectionString));
  
          //nhibernateSession = Fluently.Configure().Database(MsSqlConfiguration.MsSql2005.ConnectionString(ConfigurationManager.AppSettings[msSqlConnectionString]))
          //                              .Mappings(m =&gt; m.AutoMappings.Add(AutoMap.AssemblyOf&lt;T_ABWEICHUNGEN&gt;().IgnoreBase&lt;BaseClass&gt;)).BuildSessionFactory();
  
          nhibernateSession = Fluently.Configure().Database(MsSqlConfiguration.MsSql2005.ConnectionString(ConfigurationManager.AppSettings[msSqlConnectionString]))
                                     .Mappings(m =&gt; m.AutoMappings.Add(AutoMap.Assembly(System.Reflection.Assembly.GetExecutingAssembly())
                                     .Override&lt;T_ABWEICHUNGEN&gt;(map =&gt;map.Map(d =&gt; d.A08_STATUS_FILE).Length(2147483647))
                                     .IgnoreBase(typeof(BaseClass))
                                     .IgnoreBase(typeof(IDColumn))
                                     .IgnoreBase(typeof(MsSqlQuery))
                                     .IgnoreBase(typeof(MsSqlParamCollection))
                                     .IgnoreBase(typeof(AbweichungStatus))
                                     )).BuildSessionFactory();
          return nhibernateSession;
      }
  }
  </code></pre>
  
  <hr>
  
  <p>thanks so far for the response - helped me so far.
  But - is there a way to get this solved more 'dynamicly'?</p>
  
  <p>For example:</p>
  
  <p>I want to declare a custom attribute called <code>[ReadOnlyDbField]</code> now declare all properties of the entity with this cusomt attribute to say: Just read this value and do not update / insert it.</p>
  
  <p>Basically i want to say in the configuration</p>
  
  <pre><code>Map all properties with the custom attribute [ReadOnlyDbField] to Not.Insert().Not.Update()
  </code></pre>
  
  <p>Is there a way to implement this?</p>