当我尝试将事件保存到商店时,出现以下异常:
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);
}
}
有谁知道为什么会这样?