internal async Task LoadOutputDataAsync <T>(DbContext context, Type type, 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 = (typeof(T) == type) ? QueryOutputTable <T>(context, sqlQuery).ToList() : QueryOutputTable(context, type, sqlQuery).Cast <T>().ToList(); UpdateEntitiesIdentity(type, entities, entitiesWithOutputIdentity); } if (BulkConfig.CalculateStats) { int numberUpdated = await GetNumberUpdatedAsync(context, cancellationToken).ConfigureAwait(false); int numberDeleted = await GetNumberDeletedAsync(context, cancellationToken).ConfigureAwait(false); BulkConfig.StatsInfo = new StatsInfo { StatsNumberUpdated = numberUpdated, StatsNumberDeleted = numberDeleted, StatsNumberInserted = entities.Count - numberUpdated - numberDeleted }; } }
protected IQueryable <T> QueryOutputTable <T>(DbContext context) where T : class { string q = SqlQueryBuilder.SelectFromOutputTable(this); var query = context.Set <T>().FromSql(q); var queryOrdered = OrderBy(query, this.PrimaryKeys[0]); return(queryOrdered); }
protected IQueryable <T> QueryOutputTable <T>(DbContext context) where T : class { string q = SqlQueryBuilder.SelectFromOutputTable(this); var query = context.Set <T>().FromSql(q); var queryOrdered = OrderBy(query, PrimaryKeys[0]); // ALTERNATIVELY OrderBy with DynamicLinq ('using System.Linq.Dynamic.Core;' NuGet required) that eliminates need for custom OrderBy<T> method with Expression. //var queryOrdered = query.OrderBy(PrimaryKeys[0]); return(queryOrdered); }
public async Task LoadOutputDataAsync <T>(DbContext context, IList <T> entities) where T : class { if (BulkConfig.SetOutputIdentity && HasSinglePrimaryKey) { string sqlQuery = SqlQueryBuilder.SelectFromOutputTable(this); var entitiesWithOutputIdentity = await QueryOutputTableAsync <T>(context, sqlQuery).ToListAsync().ConfigureAwait(false); UpdateEntitiesIdentity(entities, entitiesWithOutputIdentity); } if (BulkConfig.CalculateStats) { int numberUpdated = await GetNumberUpdatedAsync(context); 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/EFCore.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 { if (BulkConfig.SetOutputIdentity && HasSinglePrimaryKey) { 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 }; } }
// Compiled queries created manually to avoid EF Memory leak bug when using EF with dynamic SQL: // https://github.com/borisdj/EFCore.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 = PropertyColumnNamesDict.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 }; } }
internal void LoadOutputData <T>(DbContext context, Type type, 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 = (typeof(T) == type) ? QueryOutputTable <T>(context, sqlQuery).ToList() : QueryOutputTable(context, type, sqlQuery).Cast <T>().ToList(); UpdateEntitiesIdentity(type, entities, entitiesWithOutputIdentity); } if (BulkConfig.CalculateStats) { int numberUpdated = GetNumberUpdated(context); int numberDeleted = GetNumberDeleted(context); BulkConfig.StatsInfo = new StatsInfo { StatsNumberUpdated = numberUpdated, StatsNumberDeleted = numberDeleted, StatsNumberInserted = entities.Count - numberUpdated - numberDeleted }; } }
protected IQueryable <T> QueryOutputTable <T>(DbContext context) where T : class { var query = context.Set <T>().FromSql <T>(SqlQueryBuilder.SelectFromOutputTable(this)); return(OrderBy(query, this.PrimaryKeys[0])); }