Exemple #1
0
        public async Task LoadOutputDataAsync <T>(DbContext context, IList <T> entities) where T : class
        {
            if (BulkConfig.SetOutputIdentity && HasSinglePrimaryKey)
            {
                var sqlQuery = SqlQueryBuilder.SelectFromOutputTable(this);
                var entitiesWithOutputIdentity = await QueryOutputTableAsync <T>(context, sqlQuery).ToListAsync().ConfigureAwait(false);

                UpdateEntitiesIdentity(entities, entitiesWithOutputIdentity);
            }
            if (BulkConfig.CalculateStats)
            {
                var numberUpdated = await GetNumberUpdatedAsync(context);

                BulkConfig.StatsInfo = new StatsInfo
                {
                    StatsNumberUpdated  = numberUpdated,
                    StatsNumberInserted = entities.Count - numberUpdated
                };
            }
        }
Exemple #2
0
        // 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)
            {
                var sqlQuery = SqlQueryBuilder.SelectFromOutputTable(this);
                var entitiesWithOutputIdentity = QueryOutputTable <T>(context, sqlQuery).ToList();
                UpdateEntitiesIdentity(entities, entitiesWithOutputIdentity);
            }

            if (!BulkConfig.CalculateStats)
            {
                return;
            }

            SqlQueryBuilder.SelectCountIsUpdateFromOutputTable(this);

            var numberUpdated = GetNumberUpdated(context);

            BulkConfig.StatsInfo = new StatsInfo
            {
                StatsNumberUpdated  = numberUpdated,
                StatsNumberInserted = entities.Count - numberUpdated
            };
        }