public static CoreHistory CreateCoreHistory(IEntityExtend entity, HistoryActionType action, DateTime?timestamp, DecorateCoreHistory decorate)
        {
            if (!InformationCenter.States.TransactionInfo.ApplicationTransactionIdentifier.HasValue)
            {
                //TODO: throw;
            }

            CoreHistory ret = null;

            ret = new CoreHistory();
            ret.ApplicationTransactionID = InformationCenter.States.TransactionInfo.ApplicationTransactionIdentifier.Value;
            ret.EntityTypeID             = entity.EntityTypeID;
            ret.EntityID   = entity.EntityID;
            ret.ActionType = action;
            if (!timestamp.HasValue)
            {
                timestamp = DateTime.Now;
            }
            ret.Timestamp = timestamp.Value;
            if (decorate != null)
            {
                decorate(ret);
            }

            using (HistoryContext ctx = HistoryContext.CreateInstance())
            {
                ctx.AddToCoreHistorySet(ret);
                ctx.SaveChanges();
            }

            return(ret);
        }
        private void AddEntityHistories(ObjectContext ctx, EntityState state, HistoryActionType action)
        {
            IEnumerable <EntityWrapper> entities = this.Entities.Where(x => x.State == state);

            foreach (EntityWrapper entityWrapper in entities)
            {
                if ((entityWrapper.Entity is EntityObject) && (entityWrapper.Entity is IEntityExtend))
                {
                    CoreHistory coreHistory = HistoryManager.CreateCoreHistory((IEntityExtend)entityWrapper.Entity, action, null, null);
                    if (entityWrapper.Entity is IWithHistory)
                    {
                        IList <IHistory> histories = ((IWithHistory)entityWrapper.Entity).CreateHistoryEntities(coreHistory);
                        foreach (IHistory history in histories)
                        {
                            this.GetHistoryEntities(entityWrapper.Key).Add(history);
                            ctx.AddObject(history.EntitySetName, history);
                        }
                    }
                }
            }
        }