我正在使用 EF Core 内存数据库,并尝试在使用事务的方法上运行单元测试:
using (var transaction = await _context.Database.BeginTransactionAsync())
{
_context.Update(item);
result = await _context.SaveChangesAsync();
// some other stuff
transaction.Commit();
}
然而,测试运行器显示以下错误:
System.InvalidOperationException: Warning as error exception for warning 'InMemoryEventId.TransactionIgnoredWarning': Transactions are not supported by the in-memory store. See http://go.microsoft.com/fwlink/?LinkId=800142 To suppress this Exception use the DbContextOptionsBuilder.ConfigureWarnings API. ConfigureWarnings can be used when overriding the DbContext.OnConfiguring method or using AddDbContext on the application service provider.
我该如何解决这个错误?