Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I modified the code from the following link to be more efficient and used it in my application. It is quite convenient because you can just put it in a partial class on top of your current autogenerated class. Instead of <code>InsertOnSubmit</code> add entities to a list, and instead of <code>SubmitChanges</code> call <code>YourDataContext.BulkInsertAll(list)</code>.</p> <p><a href="http://www.codeproject.com/Tips/297582/Using-bulk-insert-with-your-linq-to-sql-datacontex">http://www.codeproject.com/Tips/297582/Using-bulk-insert-with-your-linq-to-sql-datacontex</a></p> <pre><code>partial void OnCreated() { CommandTimeout = 5 * 60; } public void BulkInsertAll&lt;T&gt;(IEnumerable&lt;T&gt; entities) { using( var conn = new SqlConnection(Connection.ConnectionString)) { conn.Open(); Type t = typeof(T); var tableAttribute = (TableAttribute)t.GetCustomAttributes( typeof(TableAttribute), false).Single(); var bulkCopy = new SqlBulkCopy(conn) { DestinationTableName = tableAttribute.Name }; var properties = t.GetProperties().Where(EventTypeFilter).ToArray(); var table = new DataTable(); foreach (var property in properties) { Type propertyType = property.PropertyType; if (propertyType.IsGenericType &amp;&amp; propertyType.GetGenericTypeDefinition() == typeof(Nullable&lt;&gt;)) { propertyType = Nullable.GetUnderlyingType(propertyType); } table.Columns.Add(new DataColumn(property.Name, propertyType)); } foreach (var entity in entities) { table.Rows.Add( properties.Select( property =&gt; property.GetValue(entity, null) ?? DBNull.Value ).ToArray()); } bulkCopy.WriteToServer(table); } } private bool EventTypeFilter(System.Reflection.PropertyInfo p) { var attribute = Attribute.GetCustomAttribute(p, typeof(AssociationAttribute)) as AssociationAttribute; if (attribute == null) return true; if (attribute.IsForeignKey == false) return true; return false; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload