public async Task LoadOutputDataAsync <T>(DbContext context, IList <T> entities, CancellationToken cancellationToken) where T : class { bool hasIdentity = OutputPropertyColumnNamesDict.Any(a => a.Value == IdentityColumnName); if (BulkConfig.SetOutputIdentity && hasIdentity) { string sqlQuery = SqlQueryBuilder.SelectFromOutputTable(this); //var entitiesWithOutputIdentity = await QueryOutputTableAsync<T>(context, sqlQuery).ToListAsync(cancellationToken).ConfigureAwait(false); // TempFIX var entitiesWithOutputIdentity = QueryOutputTable <T>(context, sqlQuery).ToList(); UpdateEntitiesIdentity(entities, entitiesWithOutputIdentity); } if (BulkConfig.CalculateStats) { int numberUpdated = await GetNumberUpdatedAsync(context, cancellationToken).ConfigureAwait(false); BulkConfig.StatsInfo = new StatsInfo { StatsNumberUpdated = numberUpdated, StatsNumberInserted = entities.Count - numberUpdated }; } }
// Compiled queries created manually to avoid EF Memory leak bug when using EF with dynamic SQL: // https://github.com/borisdj/Portal.Data.BulkExtensions/issues/73 // Once the following Issue gets fixed(expected in EF 3.0) this can be replaced with code segment: DirectQuery // https://github.com/aspnet/EntityFrameworkCore/issues/12905 #region CompiledQuery public void LoadOutputData <T>(DbContext context, IList <T> entities) where T : class { bool hasIdentity = OutputPropertyColumnNamesDict.Any(a => a.Value == IdentityColumnName); if (BulkConfig.SetOutputIdentity && hasIdentity) { string sqlQuery = SqlQueryBuilder.SelectFromOutputTable(this); var entitiesWithOutputIdentity = QueryOutputTable <T>(context, sqlQuery).ToList(); UpdateEntitiesIdentity(entities, entitiesWithOutputIdentity); } if (BulkConfig.CalculateStats) { string sqlQueryCount = SqlQueryBuilder.SelectCountIsUpdateFromOutputTable(this); int numberUpdated = GetNumberUpdated(context); BulkConfig.StatsInfo = new StatsInfo { StatsNumberUpdated = numberUpdated, StatsNumberInserted = entities.Count - numberUpdated }; } }