Exemplo n.º 1
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()
                {
                }
            };

            tableInfo.BulkConfig.OperationType = operationType;

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

            if (tableInfo.BulkConfig.UseTempDB == true && !isExplicitTransaction && (operationType != OperationType.Insert || tableInfo.BulkConfig.SetOutputIdentity))
            {
                throw new InvalidOperationException("UseTempDB when set then BulkOperation has to be inside Transaction. More info in README of the library in GitHub.");
                // 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, entities, isDeleteOperation);
            return(tableInfo);
        }
Exemplo n.º 2
0
        public static TableInfo CreateInstance <T>(DbContext context, IList <T> entities, OperationType operationType, BulkConfig bulkConfig)
        {
            var tableInfo         = new TableInfo();
            var isDeleteOperation = operationType == OperationType.Delete;

            tableInfo.NumberOfEntities = entities.Count;
            tableInfo.LoadData <T>(context, isDeleteOperation);
            tableInfo.BulkConfig = bulkConfig ?? new BulkConfig();
            return(tableInfo);
        }
Exemplo n.º 3
0
        public static void Execute <T>(DbContext context, IList <T> entities, OperationType operationType, BulkConfig bulkConfig) where T : class
        {
            var tableInfo         = new TableInfo();
            var isDeleteOperation = operationType == OperationType.Delete;

            tableInfo.NumberOfEntities = entities.Count;
            tableInfo.LoadData <T>(context, isDeleteOperation);
            tableInfo.BulkConfig = bulkConfig ?? new BulkConfig();

            if (operationType == OperationType.Insert && !tableInfo.BulkConfig.SetOutputIdentity)
            {
                SqlBulkOperation.Insert <T>(context, entities, tableInfo);
            }
            else
            {
                SqlBulkOperation.Merge <T>(context, entities, tableInfo, operationType);
            }
        }
Exemplo n.º 4
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()
            };

            if (operationType != OperationType.Insert)
            {
                tableInfo.BulkConfig.UseTempDB = false; // TempDB can only be used with Insert.
                // Other Operations done with customTemp table.
                // If using tempdb[#] throws exception: 'Cannot access destination table' (gets Droped too early, probably because transaction ends)
            }

            var isDeleteOperation = operationType == OperationType.Delete;

            tableInfo.LoadData <T>(context, isDeleteOperation);
            return(tableInfo);
        }
Exemplo n.º 5
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()
            };

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

            if (tableInfo.BulkConfig.UseTempDB == true && !isExplicitTransaction && (operationType != OperationType.Insert || tableInfo.BulkConfig.SetOutputIdentity))
            {
                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 Droped too early because transaction ends before operation is finished)
            }

            var isDeleteOperation = operationType == OperationType.Delete;

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