Skip to content

Commit

Permalink
Order by timestamp (#35)
Browse files Browse the repository at this point in the history
* Always order events by timestamp

* Add required class constraint to metadata type

Without this, EF fails with an exception when it tries to cast from
TEventMetadata to IEventMetadata<TStreamId>. I'm still not sure why
EF is happier this way, but hey - it seems to work...
  • Loading branch information
Tomas Lycken committed Nov 1, 2017
1 parent 950a958 commit 432a03b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class EventStoreFixture<TId, TStreamId, TEvent, TEventMetadata, TPersiste
where TStreamId : IEquatable<TStreamId>
where TEvent : class, TEventMetadata, IMutableEvent<TStreamId>, new()
where TPersistedEvent : class, TEventMetadata, IPersistedEvent<TStreamId>, new()
where TEventMetadata : IEventMetadata<TStreamId>
where TEventMetadata : class, IEventMetadata<TStreamId>
{
public EventStoreFixture()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace RdbmsEventStore.EntityFramework.Tests.Infrastructure
public class EventStoreTestBase<TId, TStreamId, TEvent, TEventMetadata, TPersistedEvent> : IClassFixture<EventStoreFixture<TId, TStreamId, TEvent, TEventMetadata, TPersistedEvent>>, IDisposable
where TId : IEquatable<TId>
where TStreamId : IEquatable<TStreamId>
where TEventMetadata : IEventMetadata<TStreamId>
where TEventMetadata : class, IEventMetadata<TStreamId>
where TEvent : class, TEventMetadata, IMutableEvent<TStreamId>, new()
where TPersistedEvent : class, TEventMetadata, IPersistedEvent<TStreamId>, new()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class EntityFrameworkEventStore<TId, TStreamId, TContext, TEvent, TEventM
where TContext : DbContext, IEventDbContext<TPersistedEvent>
where TEvent : class, TEventMetadata, IMutableEvent<TStreamId>, new()
where TPersistedEvent : class, IPersistedEvent<TStreamId>, TEventMetadata, new()
where TEventMetadata : IEventMetadata<TStreamId>
where TEventMetadata : class, IEventMetadata<TStreamId>
{
private readonly TContext context;
private readonly IEventFactory<TStreamId, TEvent> _eventFactory;
Expand All @@ -35,6 +35,7 @@ public async Task<IEnumerable<TEvent>> Events(Func<IQueryable<TEventMetadata>, I
var storedEvents = await context.Events
.AsNoTracking()
.Apply(query)
.OrderBy(e => e.Timestamp)
.ToListAsync();

var events = storedEvents
Expand All @@ -52,7 +53,9 @@ public async Task<IEnumerable<TEvent>> Events(TStreamId streamId, Func<IQueryabl
.Where(e => e.StreamId.Equals(streamId))
.AsNoTracking()
.Apply(query)
.OrderBy(e => e.Timestamp)
.ToListAsync();

var events = storedEvents
.Cast<TPersistedEvent>()
.Select(_serializer.Deserialize);
Expand Down

0 comments on commit 432a03b

Please sign in to comment.