public void SaveCollection <T>(IEnumerable <TObject> collection) { if (collection != null && collection.Count() > 0) { try { foreach (var item in collection) { //try //{ // //Add(item); _context.Set <TObject>().Add(item); // _context.SaveChanges(); //} //catch (Exception exp) //{ // throw; //} } _context.SaveChanges(); } catch (Exception) { throw; } } }
public static FXWinV2Entities BulkInserts <T>(this FXWinV2Entities context, T entity, int count, int batchSize) where T : class { context.Set <T>().Add(entity); if (count % batchSize == 0) { context.SaveChanges(); context.Dispose(); context = new FXWinV2Entities(); // This is optional context.Configuration.AutoDetectChangesEnabled = false; } return(context); }