InstanceEntityBase TableEntityToHistoryEvent(AzureTableCompositeTableEntity entity)
        {
            AzureTableOrchestrationHistoryEventEntity workItemEntity     = null;
            AzureTableOrchestrationStateEntity        historyStateEntity = null;

            if ((workItemEntity = entity as AzureTableOrchestrationHistoryEventEntity) != null)
            {
                return(new OrchestrationWorkItemInstanceEntity
                {
                    InstanceId = workItemEntity.InstanceId,
                    ExecutionId = workItemEntity.ExecutionId,
                    SequenceNumber = workItemEntity.SequenceNumber,
                    EventTimestamp = workItemEntity.TaskTimeStamp,
                    HistoryEvent = workItemEntity.HistoryEvent
                });
            }
            else if ((historyStateEntity = entity as AzureTableOrchestrationStateEntity) != null)
            {
                return(new OrchestrationStateInstanceEntity {
                    State = historyStateEntity.State
                });
            }
            else
            {
                throw new InvalidOperationException($"Invalid entity event type: {entity.GetType()}");
            }
        }
 OrchestrationWorkItemInstanceEntity TableHistoryEntityToWorkItemEvent(AzureTableOrchestrationHistoryEventEntity entity)
 {
     return(new OrchestrationWorkItemInstanceEntity
     {
         InstanceId = entity.InstanceId,
         ExecutionId = entity.ExecutionId,
         SequenceNumber = entity.SequenceNumber,
         EventTimestamp = entity.TaskTimeStamp,
         HistoryEvent = entity.HistoryEvent
     });
 }
        internal override IEnumerable <ITableEntity> BuildDenormalizedEntities()
        {
            var entity = new AzureTableOrchestrationHistoryEventEntity(InstanceId,
                                                                       ExecutionId,
                                                                       SequenceNumber,
                                                                       TaskTimeStamp, HistoryEvent);

            entity.PartitionKey = AzureTableConstants.InstanceHistoryEventPrefix +
                                  AzureTableConstants.JoinDelimiter + InstanceId;
            entity.RowKey = AzureTableConstants.InstanceHistoryEventRowPrefix +
                            AzureTableConstants.JoinDelimiter +
                            ExecutionId + AzureTableConstants.JoinDelimiter + SequenceNumber;

            return(new[] { entity });
        }