public async Task <int> Save(IAggregateRoot aggregateRoot)
        {
            var dt = new DataTable();

            dt.Columns.Add("Data", typeof(string));

            foreach (var e in aggregateRoot.GetEvents())
            {
                dt.Rows.Add(e.Serialize());
            }

            using (var connection = new SqlConnection(_connectionString))
            {
                var argumentObject = new
                {
                    AggregateID = aggregateRoot.Id,
                    Name        = StreamName(aggregateRoot.GetType(), aggregateRoot.Id),
                    Type        = aggregateRoot.GetType().AssemblyQualifiedName,
                    aggregateRoot.Version,
                    Batch = dt.AsTableValuedParameter("EventValueType")
                };

                return(await connection.ExecuteAsync("Event_Ins", argumentObject, commandType : CommandType.StoredProcedure));
            }
        }
示例#2
0
        public Task Save(IAggregateRoot aggregateRoot)
        {
            var events = aggregateRoot
                         .GetEvents()
                         .Select(ToEventData);

            return(eventStoreConnection.AppendToStreamAsync(StreamName(aggregateRoot.GetType(), aggregateRoot.Id), aggregateRoot.Version, events));
        }
示例#3
0
    public Task SaveAsync(IAggregateRoot aggregateRoot, CancellationToken ct)
    {
        var events = aggregateRoot
                     .GetEvents()
                     .Select(ToEventData);

        return(_eventStore.AppendToStreamAsync(
                   StreamName(aggregateRoot.GetType(), aggregateRoot.Id),
                   StreamRevision.FromInt64(aggregateRoot.Version),
                   events,
                   cancellationToken: ct
                   ));
    }