예제 #1
0
        public IEnumerable <StoredEvent> GetEvents <TKey>(TKey eventId, int afterVersion = 0)
            where TKey : IEquatable <TKey>
        {
            var query  = $"SELECT * FROM {TableName} WHERE EventId = '{eventId}' AND Version >= {afterVersion}";
            var result = dbContext.QueryAsync(query).Result;

            return(result == null ? new StoredEvent[] { } : SerieToStoredEvent(result));
        }
예제 #2
0
        public Memento GetMemento <TKey>(TKey aggregateId)
            where TKey : IEquatable <TKey>
        {
            var query  = $"SELECT * FROM {TableName} WHERE AggregateId = '{aggregateId}' ORDER BY time DESC LIMIT 1";
            var result = dbContext.QueryAsync(query).Result;

            return(result == null ? null : new Memento()
            {
                AggregateId = result.Values[0][result.Columns.IndexOf("AggregateId")].ToString(),
                Version = int.Parse(result.Values[0][result.Columns.IndexOf("Version")].ToString()),
                Data = result.Values[0][result.Columns.IndexOf("Data")].ToString().Replace(@"\", string.Empty),
                Timestamp = DateTime.Parse(result.Values[0][0].ToString())
            });
        }