Ejemplo n.º 1
0
 protected async Task<int> GetNumberUpdatedAsync(DbContext context, CancellationToken cancellationToken)
 {
     var resultParameters = new List<SqlParameter> { new SqlParameter("@result", SqlDbType.Int) { Direction = ParameterDirection.Output } };
     string sqlQueryCount = SqlQueryBuilder.SelectCountIsUpdateFromOutputTable(this);
     await context.Database.ExecuteSqlRawAsync($"SET @result = ({sqlQueryCount});", resultParameters, cancellationToken).ConfigureAwait(false); // TODO cancellationToken if Not
     return (int)resultParameters.FirstOrDefault().Value;
 }
Ejemplo n.º 2
0
 protected int GetNumberUpdated(DbContext context)
 {
     var resultParameter = new SqlParameter("@result", SqlDbType.Int) { Direction = ParameterDirection.Output };
     string sqlQueryCount = SqlQueryBuilder.SelectCountIsUpdateFromOutputTable(this);
     context.Database.ExecuteSqlRaw($"SET @result = ({sqlQueryCount});", resultParameter);
     return (int)resultParameter.Value;
 }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        protected int GetNumberUpdated(DbContext context)
        {
            var resultParameter = SqlClientHelper.CreateParameter(context.Database.GetDbConnection());

            resultParameter.ParameterName = "@result";
            resultParameter.DbType        = DbType.Int32;
            resultParameter.Direction     = ParameterDirection.Output;
            string sqlQueryCount = SqlQueryBuilder.SelectCountIsUpdateFromOutputTable(this);

            context.Database.ExecuteSqlRaw($"SET @result = ({sqlQueryCount});", resultParameter);
            return((int)resultParameter.Value);
        }
Ejemplo n.º 5
0
        protected async Task <int> GetNumberUpdatedAsync(DbContext context, CancellationToken cancellationToken)
        {
            var resultParameters = new List <IDbDataParameter>();
            var p = SqlClientHelper.CreateParameter(context.Database.GetDbConnection());

            p.ParameterName = "@result";
            p.DbType        = DbType.Int32;
            p.Direction     = ParameterDirection.Output;
            resultParameters.Add(p);
            string sqlQueryCount = SqlQueryBuilder.SelectCountIsUpdateFromOutputTable(this);
            await context.Database.ExecuteSqlRawAsync($"SET @result = ({sqlQueryCount});", resultParameters, cancellationToken).ConfigureAwait(false); // TODO cancellationToken if Not

            return((int)resultParameters.FirstOrDefault().Value);
        }
Ejemplo n.º 6
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)
            {
                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
                };
            }
        }
Ejemplo n.º 7
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
        {
            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
                };
            }
        }