当我尝试将事件保存到商店时,我得到以下异常:
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);
}
}
有谁知道为什么会这样?
答案 0 :(得分:1)
该消息具有误导性。这次检查时抛出here ......
attempt.StreamId != Guid.Empty && attempt.CommitId != Guid.Empty
是假的。所以它应该说:CommitId
和StreamId
都不能为空。