title: NHibernate Insert Into Table
body: <p>How i can insert data to table with CreateQuery()?</p>
  
  <p>c# class</p>
  
  <pre><code>namespace NHibernateTutorial
  {
      public class Customer
      {
          public virtual int CustomerId { get; set; }
          public virtual string FirstName { get; set; }
          public virtual string LastName { get; set; }           
      }
  }
  </code></pre>
  
  <p>mapping xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                  assembly="NHibernateTutorial"
                  namespace="NHibernateTutorial"&gt;
    &lt;class name="Customer"&gt;
      &lt;cache usage="read-write"/&gt;
      &lt;id name="CustomerId"&gt;
        &lt;generator class="native" /&gt;
      &lt;/id&gt;
      &lt;property name="FirstName" /&gt;
      &lt;property name="LastName" /&gt;    
    &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>My program class</p>
  
  <pre><code>    var configuartion = new Configuration();
                  configuartion.DataBaseIntegration(x =&gt;
                      {
                          x.ConnectionString = @"Data Source=NH;Initial Catalog=NHibernate;Integrated Security=False;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False";
                          x.Driver&lt;SqlClientDriver&gt;();
                          x.Dialect&lt;MsSql2012Dialect&gt;();
                          x.LogFormattedSql = true;
                          x.LogSqlInConsole = true;
                          x.AutoCommentSql = true;
                      });
  
                  configuartion.AddAssembly(Assembly.GetExecutingAssembly());
  
                  var sessionFactory = configuartion.BuildSessionFactory();
                  using (var session = sessionFactory.OpenSession())
                  { 
                   var query = session.CreateQuery("INSERT INTO Customer (FirstName, LastName) select i.FirstName, i.LastName from CustomerOld i"); 
                   query.ExecuteUpdate();
                  }
  </code></pre>
  
  <p>In this example i copy row from another table, but i need create new row, how i can do this? </p>