我在我的应用程序中使用大事务。此事务在不同的表中包含很多SaveChanges()。
我正在使用存储库模式,这是我所拥有的伪代码:
public async Task<Event> AddEvent(int eventId, string eventData)
{
using(var transaction = await _eventRepository.BeginTransactionAsync())
{
try
{
//some more operations..
await EventFactory.HandleEventAsync(eventId) // <-- This line call factory to do alot of things in diffrent tables with using SaveChanges() methods and so it uses other repositories
//some more operations..
}
catch(Exception ex)
{
transaction.Rollback()
}
}
}
我在每个API调用的所有存储库中使用一个上下文。关键是有时似乎事务没有回滚更改。然而,这确实是非确定性的,因为这种情况每天都会在生产中发生一次〜。
我正在使用Entity Framework Core 1.1。
我真的无法在代码中找到问题,因为当某些功能失败时会出现回滚,但有时我会在数据库中看到异常数据。
使用EF Core,somone是否面临类似的问题?