public DataTransaction ForceChangeStage(IEnumerable <Entity> entities, EntityWorkflowStage stage, DataTransaction dataTransaction)
            {
                using (DataTransactionSwitch transaction = new DataTransactionSwitch(EntitySet.Connection, dataTransaction))
                {
                    foreach (Entity entity in entities)
                    {
                        if (!GetEntityStageId(entity, transaction, out object stageId))
                        {
                            throw new ModelException(ErrorLevel.Information, "Нельзя сменить стадию объекта на {0}", stage);
                        }

                        if (!entity.OnWorkflowStageChanging(stage, null, null))
                        {
                            return(null);
                        }

                        entity.Edit(transaction);
                        if (entity.EntitySet.Extension != null && !entity.EntitySet.Extension.OnWorkflowStageChanging(entity, stage, null, null, null))
                        {
                            return(null);
                        }

                        SetEntityStageId(entity, stage.Id, "Назначение стадии", null, null);
                    }

                    transaction.Commit();

                    return(transaction.Transaction);
                }
            }
            public IEnumerable <EntityWorkflowStageChange> GetStageChanges(EntityWorkflow workflow, Entity entity, IEnumerable <WorkflowStageChangeData> dataList)
            {
                if (HistoryConfiguration == null || !GetEntityStageId(entity, null, out _))
                {
                    yield break;
                }

                EntitySet historySet = entity.Connection.GetEntitySet(HistoryConfiguration.EntitySetGuid)?.CreateEntitySet();

                if (historySet != null)
                {
                    EntityLoadParameters loadParameters = new EntityLoadParameters(historySet);
                    if (HistoryConfiguration.ResponsibleLinkGuid != Guid.Empty)
                    {
                        loadParameters.AddLink(HistoryConfiguration.ResponsibleLinkGuid);
                    }
                    loadParameters.Filter = new EntitySetFilter(historySet.GetInfo());
                    loadParameters.Filter.And(HistoryConfiguration.OwnerLinkGuid, "=", entity.Guid);
                    if (HistoryConfiguration.EntityTypeGuid != Guid.Empty)
                    {
                        loadParameters.Filter.And(SystemPropertyItem.Type, "=", HistoryConfiguration.EntityTypeGuid);
                    }

                    IEntityCollection <Entity>    historyItems     = historySet.GetEntities(loadParameters);
                    EntityCollection <LinkEntity> responsibleLinks = HistoryConfiguration.ResponsibleLinkGuid != Guid.Empty ?
                                                                     historyItems.GetLinks(HistoryConfiguration.ResponsibleLinkGuid) : null;

                    foreach (Entity historyItem in historyItems)
                    {
                        EntityWorkflowStage stage = workflow.GetStage(historyItem[HistoryConfiguration.StagePropertyGuid]);
                        Guid userGuid             = responsibleLinks == null ?
                                                    historyItem.CreatedBy : (responsibleLinks.FindOne <Entity>(historyItem.Guid)?.Guid ?? Guid.Empty);
                        DateTime changeTime = HistoryConfiguration.DateTimePropertyGuid == Guid.Empty ?
                                              historyItem.Created.GetValueOrDefault() : (DateTime)historyItem[HistoryConfiguration.DateTimePropertyGuid];
                        string comment = HistoryConfiguration.CommentPropertyGuid == Guid.Empty ?
                                         string.Empty : (historyItem[HistoryConfiguration.CommentPropertyGuid]?.ToString() ?? string.Empty);
                        yield return(new EntityWorkflowStageChange(workflow, stage, null, userGuid, changeTime, historyItem.Name, comment));
                    }
                }
            }