Ejemplo n.º 1
0
        /// <summary>
        /// Does a direct bulk UPDATE.
        /// Example: rockContext.BulkUpdate( personQuery, p => new Person { LastName = "Decker" } );
        /// NOTE: This bypasses the Rock and a bunch of the EF Framework and automatically commits the changes to the database
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="queryable">The queryable for the records to update</param>
        /// <param name="updateFactory">Linq expression to specify the updated property values</param>
        /// <returns>the number of records updated</returns>
        public virtual int BulkUpdate <T>(IQueryable <T> queryable, Expression <Func <T, T> > updateFactory) where T : class
        {
            var         currentDateTime       = RockDateTime.Now;
            PersonAlias currentPersonAlias    = this.GetCurrentPersonAlias();
            var         rockExpressionVisitor = new RockBulkUpdateExpressionVisitor(currentDateTime, currentPersonAlias);

            rockExpressionVisitor.Visit(updateFactory);
            int recordsUpdated = queryable.Update(updateFactory);

            return(recordsUpdated);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Does a direct bulk UPDATE.
        /// Example: rockContext.BulkUpdate( personQuery, p => new Person { LastName = "Decker" } );
        /// NOTE: This bypasses the Rock and a bunch of the EF Framework and automatically commits the changes to the database
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="queryable">The queryable for the records to update</param>
        /// <param name="updateFactory">Linq expression to specify the updated property values</param>
        /// <returns>the number of records updated</returns>
        public virtual int BulkUpdate <T>(IQueryable <T> queryable, Expression <Func <T, T> > updateFactory) where T : class
        {
            var         currentDateTime       = RockDateTime.Now;
            PersonAlias currentPersonAlias    = this.GetCurrentPersonAlias();
            var         rockExpressionVisitor = new RockBulkUpdateExpressionVisitor(currentDateTime, currentPersonAlias);
            var         updatedExpression     = rockExpressionVisitor.Visit(updateFactory) as Expression <Func <T, T> > ?? updateFactory;
            int         recordsUpdated        = queryable.Update(updatedExpression, batchUpdateBuilder =>
            {
                batchUpdateBuilder.Executing = (e) => { e.CommandTimeout = this.Database.CommandTimeout ?? 30; };
            });

            return(recordsUpdated);
        }