コード例 #1
0
 public int GetLastSequence(Guid aggregateId)
 {
     using (var context = new EventStoreContext(ConnectionString.Get()))
     {
         var maxSequence = context.Database.SqlQuery <int?>($"SELECT MAX(Sequence) FROM dbo.Event where AggregateId = '{aggregateId}'").FirstOrDefault();
         return(maxSequence ?? 0);
     }
 }
コード例 #2
0
 public void Save(IDomainEvent @event)
 {
     using (var context = new EventStoreContext(ConnectionString.Get()))
     {
         var dbEvent = new DbEvent(@event, _eventSerializer, _eventStamping);
         context.Events.Add(dbEvent);
         context.SaveChanges();
     }
 }
コード例 #3
0
        public IReadOnlyList <IDomainEvent> GetAllEvents()
        {
            var events = new List <IDomainEvent>();

            using (var context = new EventStoreContext(ConnectionString.Get()))
            {
                foreach (var dbEvent in context.Events.Where(a => !a.EventName.Contains("Test")))
                {
                    events.Add(_eventSerializer.Deserialize <IDomainEvent>(dbEvent.Data));
                }
            }

            return(events);
        }
コード例 #4
0
        public IReadOnlyList <IDomainEvent> GetEvents(Guid aggregateId)
        {
            var events = new List <IDomainEvent>();

            using (var context = new EventStoreContext(ConnectionString.Get()))
            {
                foreach (var dbEvent in context.Events.Where(a => a.AggregateId == aggregateId))
                {
                    events.Add(_eventSerializer.Deserialize <IDomainEvent>(dbEvent.Data));
                }
            }

            return(events);
        }