Beispiel #1
0
        /// <summary>
        /// Cleans up expired entity sets.
        /// </summary>
        /// <param name="dataMap">The data map.</param>
        private void CleanupExpiredEntitySets(JobDataMap dataMap)
        {
            var entitySetRockContext = new Rock.Data.RockContext();
            var currentDateTime      = RockDateTime.Now;
            var entitySetService     = new EntitySetService(entitySetRockContext);
            var qry = entitySetService.Queryable().Where(a => a.ExpireDateTime.HasValue && a.ExpireDateTime < currentDateTime);

            foreach (var entitySet in qry.ToList())
            {
                string deleteWarning;
                if (entitySetService.CanDelete(entitySet, out deleteWarning))
                {
                    // delete in chunks (see http://dba.stackexchange.com/questions/1750/methods-of-speeding-up-a-huge-delete-from-table-with-no-clauses)
                    bool keepDeleting = true;
                    while (keepDeleting)
                    {
                        var dbTransaction = entitySetRockContext.Database.BeginTransaction();
                        try
                        {
                            string sqlCommand = @"DELETE TOP (1000) FROM [EntitySetItem] WHERE [EntitySetId] = @entitySetId";

                            int rowsDeleted = entitySetRockContext.Database.ExecuteSqlCommand(sqlCommand, new SqlParameter("entitySetId", entitySet.Id));
                            keepDeleting = rowsDeleted > 0;
                        }
                        finally
                        {
                            dbTransaction.Commit();
                        }
                    }

                    entitySetService.Delete(entitySet);
                    entitySetRockContext.SaveChanges();
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Gets the entity set.
        /// </summary>
        /// <returns></returns>
        private EntitySet GetEntitySet()
        {
            if (_entitySet == null)
            {
                var entitySetId = GetEntitySetId();

                var rockContext      = new RockContext();
                var entitySetService = new EntitySetService(rockContext);
                _entitySet = entitySetService.Queryable().AsNoTracking().FirstOrDefault(es => es.Id == entitySetId);
            }

            return(_entitySet);
        }
Beispiel #3
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            RockContext rockContext      = new RockContext();
            var         entitySetService = new EntitySetService(rockContext);

            var entitySetPurposeGuid = Rock.SystemGuid.DefinedValue.ENTITY_SET_PURPOSE_PERSON_MERGE_REQUEST.AsGuid();

            var currentDateTime = RockDateTime.Now;
            var entitySetQry    = entitySetService.Queryable()
                                  .Where(a => a.EntitySetPurposeValue.Guid == entitySetPurposeGuid)
                                  .Where(s => !s.ExpireDateTime.HasValue || s.ExpireDateTime.Value > currentDateTime);

            SortProperty sortProperty = gList.SortProperty;

            var qryPersonEntities = entitySetService.GetEntityItems <Person>();

            var joinQry = entitySetQry.GroupJoin(qryPersonEntities, n => n.Id, o => o.EntitySetId, (a, b) => new
            {
                a.Id,
                a.ModifiedDateTime,
                a.Note,
                a.CreatedByPersonAlias,
                MergeRecords = b.Select(x => x.Item)
            });

            if (sortProperty != null)
            {
                joinQry = joinQry.Sort(sortProperty);
            }
            else
            {
                joinQry = joinQry.OrderBy(s => s.ModifiedDateTime);
            }

            gList.SetLinqDataSource(joinQry);
            gList.DataBind();
        }