当我试图将事件保存到存储时,我会得到以下异常:
The commit must be uniquely identified.rnParameter 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);
}
}
有人知道为什么会发生这种事吗?
该消息具有误导性。当这张支票。。。
attempt.StreamId != Guid.Empty && attempt.CommitId != Guid.Empty
是假的。所以应该说:CommitId
和StreamId
都不能为空。