title: SQLBulkCopy with Identity Insert in destination table
body: <p>I am trying to insert a Generic list to SQL Server with SQLBulkCopy,</p>
  
  <p>And i have trouble wit Identity Field</p>
  
  <p>I wan t my destination table to generate identity field
  How should i handle this,
  here is my code</p>
  
  <pre><code>using (var bulkCopy = new SqlBulkCopy(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
                  {
                      bulkCopy.BatchSize = (int)DetailLines;
                      bulkCopy.DestinationTableName = "dbo.tMyTable";
  
                      var table = new DataTable();
                      var props = TypeDescriptor.GetProperties(typeof(tBFFormularyStatusList))
                          //Dirty hack to make sure we only have system data types 
                          //i.e. filter out the relationships/collections
                                                 .Cast&lt;PropertyDescriptor&gt;()
                                                 .Where(propertyInfo =&gt; propertyInfo.PropertyType.Namespace.Equals("System"))
                                                 .ToArray();
                      foreach (var propertyInfo in props)
                      {
                          bulkCopy.ColumnMappings.Add(propertyInfo.Name, propertyInfo.Name);
                          table.Columns.Add(propertyInfo.Name, Nullable.GetUnderlyingType(propertyInfo.PropertyType) ?? propertyInfo.PropertyType);
                      }
  
                      var values = new object[props.Length];
                      foreach (var item in myGenericList)
                      {
                          for (var i = 0; i &lt; values.Length; i++)
                          {
                              values[i] = props[i].GetValue(item);
                          }
  
                          table.Rows.Add(values);
                      }
  
                      bulkCopy.WriteToServer(table);
                  }
  </code></pre>
  
  <h1>exception</h1>
  
  <pre><code>Property accessor 'ID' on object 'ProcessFlatFiles.DetailsClass' threw the following exception:'Object does not match target type.'
  </code></pre>
  
  <p>I have also tried </p>
  
  <pre><code>using (var bulkCopy = new SqlBulkCopy(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString, SqlBulkCopyOptions.KeepIdentity))
                  {
  </code></pre>