Exemplo n.º 1
0
        protected async Task <int> GetNumberUpdatedAsync(DbContext context)
        {
            var resultParameter = new SqlParameter("@result", SqlDbType.Int)
            {
                Direction = ParameterDirection.Output
            };
            string sqlQueryCount = SqlQueryBuilder.SelectCountIsUpdateFromOutputTable(this);
            await context.Database.ExecuteSqlCommandAsync($"SET @result = ({sqlQueryCount});", resultParameter);

            return((int)resultParameter.Value);
        }
Exemplo n.º 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
            };
        }