0

当我尝试将事件保存到商店时,出现以下异常:

The commit must be uniquely identified.\r\nParameter name: attempt

但我的代码总是为提交生成一个新的新 Guid(根据 NEventStore 示例)

public void Save(Guid aggregateId, IEnumerable<Event> events, int expectedVersion)
{
    var eventList = events as IList<Event> ?? events.ToList();

    using (var scope = new TransactionScope())
    using (var stream = store.OpenStream(aggregateId, 0, int.MaxValue))
    {
        if(stream.StreamRevision != expectedVersion)
            throw new ConcurrencyException();

        foreach (var @event in eventList)
        {
            stream.Add(new EventMessage { Body = @event });
        }

        stream.CommitChanges(Guid.NewGuid());

        scope.Complete();
    }

    foreach (var @event in eventList)
    {
        publisher.Publish(@event);
    }
}

有谁知道为什么会这样?

4

1 回答 1

1

该消息具有误导性。当这个检查时它被抛出这里......

attempt.StreamId != Guid.Empty && attempt.CommitId != Guid.Empty

是假的。所以应该说:CommitIdand都StreamId不能为空。

于 2013-12-03T20:29:11.920 回答