/// <summary> /// Merges a list of <typeparamref name="TEntity"/>. /// </summary> /// <typeparam name="TEntity">The entity type.</typeparam> /// <param name="context">The database context.</param> /// <param name="entities">The list of entities to merge.</param> /// <param name="operationType">The operation type.</param> /// <param name="config">The bulk operation configuration.</param> public static void BulkMerge <TEntity>( this DbContext context, IEnumerable <TEntity> entities, BulkMergeOperationType operationType, BulkConfig <TEntity> config = null) where TEntity : class { Core.BulkMerge.New.Execute( context, entities, operationType, config ?? new BulkConfig <TEntity>()); }
public BulkTableInfo( DbContext context, IEnumerable <TEntity> entities, BulkConfig <TEntity> config, BulkMergeOperationType operationType) { EntityMap = context.Db <TEntity>(); Config = config; OperationType = operationType; EntityCount = entities.Count(); TempTableName = string.Format("{0}{1}{2}", TempDBPrefix, EntityMap.TableName, Guid.NewGuid().ToString().Substring(0, 8)); Schema = EntityMap.Schema; TableName = EntityMap.TableName; InitIdentifierColumns(); InitOperationIncludedColumns(); InitIdentityColumn(); InitTempTableIncludedColumns(); InitTempOutputTableIncludedColumns(); }
public void Execute <TEntity>( DbContext context, IEnumerable <TEntity> entities, BulkMergeOperationType operationType, BulkConfig <TEntity> config) where TEntity : class { BulkTableInfo <TEntity> tableInfo = new BulkTableInfo <TEntity>(context, entities, config, operationType); // Creates inner transaction for the scope of the operation if the context doesn't have one. var transaction = context.InternalTransaction(); try { ExecuteCommand(context, entities, tableInfo); //Commit if internal transaction exists. transaction?.Commit(); } finally { transaction?.Dispose(); } }