예제 #1
0
 public static void BulkInsert <T>(this DbContext context, IList <T> entities, BulkConfig bulkConfig = null, Action <decimal> progress = null) where T : class
 {
     DbContextBulkTransaction.Execute(context, entities, OperationType.Insert, bulkConfig, progress);
 }
예제 #2
0
        public static TableInfo CreateInstance <T>(DbContext context, IList <T> entities, OperationType operationType, BulkConfig bulkConfig)
        {
            var tableInfo = new TableInfo
            {
                NumberOfEntities = entities.Count,
                BulkConfig       = bulkConfig ?? new BulkConfig()
            };

            var isExplicitTransaction = context.Database.GetDbConnection().State == ConnectionState.Open;

            if (tableInfo.BulkConfig.UseTempDB && !isExplicitTransaction && operationType != OperationType.Insert)
            {
                tableInfo.BulkConfig.UseTempDB = false;
                // If BulkOps is not in explicit transaction then tempDb[#] can only be used with Insert, other Operations done with customTemp table.
                // Otherwise throws exception: 'Cannot access destination table' (gets Dropped too early because transaction ends before operation is finished)
            }

            var isDeleteOperation = operationType == OperationType.Delete;

            tableInfo.LoadData <T>(context, isDeleteOperation);

            foreach (var ignoreColumn in tableInfo.BulkConfig.IgnoreColumns)
            {
                tableInfo.PropertyColumnNamesDict.Remove(ignoreColumn);
            }

            if (operationType != OperationType.Update)
            {
                return(tableInfo);
            }

            foreach (var ignoreColumn in tableInfo.BulkConfig.IgnoreColumnsUpdate)
            {
                tableInfo.PropertyColumnNamesDict.Remove(ignoreColumn);
            }

            return(tableInfo);
        }
예제 #3
0
 public static Task BulkReadAsync <T>(this DbContext context, IList <T> entities, BulkConfig bulkConfig = null, Action <decimal> progress = null) where T : class
 {
     return(DbContextBulkTransaction.ExecuteAsync(context, entities, OperationType.Read, bulkConfig, progress));
 }