public void Save(T eventSourced, string correlationId)
        {
            IVersionedEvent[] events = eventSourced.Events.ToArray();
            using (EventStoreDbContext context = this._contextFactory.Invoke()) {
                DbSet <Event> eventsSet = context.Set <Event>();
                foreach (IVersionedEvent e in events)
                {
                    eventsSet.Add(this.Serialize(e, correlationId));
                }

                context.SaveChanges();
            }

            this._eventBus.Publish(events.Select(e => new Envelope <IEvent>(e)
            {
                CorrelationId = correlationId
            }));
        }
        public T Find(Guid id)
        {
            using (EventStoreDbContext context = this._contextFactory.Invoke()) {
                var deserialized = context.Set <Event>()
                                   .Where(x => x.AggregateId == id && x.AggregateType == SourceType)
                                   .OrderBy(x => x.Version)
                                   .AsEnumerable()
                                   .Select(this.Deserialize)
                                   .AsCachedAnyEnumerable();

                if (deserialized.Any())
                {
                    return(_entityFactory.Invoke(id, deserialized));
                }

                return(null);
            }
        }