void EnsureDbCreated() { using (var dbContext = new CommandServiceDataContext(dbContextOptions)) { dbContext.Database.EnsureCreated(); } }
async Task <Event> CreateEvent <T>(string productId, string eventType, T arg) { using (var dataContext = new CommandServiceDataContext(dbContextOptions)) { var @event = new Event { Seq = Interlocked.Increment(ref seq), Data = MakeEventData(productId, eventType, arg), }; await dataContext.Events.AddAsync(@event); await dataContext.SaveChangesAsync(); return(@event); } }
void OnReplayEvents(ReplayEvents replayEvents) { using (var dataContext = new CommandServiceDataContext(dbContextOptions)) { var query = dataContext.Events .Where(evt => evt.Seq >= replayEvents.From) .AsQueryable(); if (replayEvents.To.HasValue) { query = query.Where(evt => evt.Seq <= replayEvents.To); } var events = query .OrderBy(evt => evt.Seq) .ToArray(); foreach (var @event in events) { var message = ConstructMessage <IMessage <object> >(@event); messageQueue.Publish(message); } } }