title: How to increment ID before any insert with NHibernate
body: <p>It looks like NH gets MAX(ID) only once, at first insert and then stores this value internally, this causes me some problems when other processes inserts data. Then I have not actual ID and duplicate key exception is thrown. </p>
  
  <p>Lets imagine we have table <code>Cats</code></p>
  
  <pre><code>CREATE TABLE Cats(ID int, Name varchar(25))
  </code></pre>
  
  <p>Then we have corresponding mapping done with FluentNhibernate</p>
  
  <pre><code>public class CatMap : ClassMap&lt;Cat&gt;
  {
      public CatMap()
      {
        Id(m=&gt;m.ID).GeneratedBy.Increment();
        Map(m=&gt;.Name);
      }
  }
  </code></pre>
  
  <p>All I want to achieve is to insert my <code>Cat</code> records with ID's generated by NHibernate using <code>SELECT MAX(ID) FROM Cats</code> <strong>before any</strong> insert. Executing Session.Flush after any commit dosnt work. I'v done some investigation using SQL Server profiler, and this sql stetement is executed only once (at first insert) - other inserts doesnt force to retreive actual MAX(ID). I know that other algorithms like HiLo are better, but I cant replace it.</p>