How to suppress InMemoryEventId.TransactionIgnoredWarning when unit testing with in-memory database with transactions?

In the code where you declare the in-memory database, configure the context to ignore that error as follows:

public MyDbContext GetContextWithInMemoryDb()
{
    var options = new DbContextOptionsBuilder<MyDbContext>()
        .UseInMemoryDatabase(Guid.NewGuid().ToString())
        // don't raise the error warning us that the in memory db doesn't support transactions
        .ConfigureWarnings(x => x.Ignore(InMemoryEventId.TransactionIgnoredWarning))
        .Options;

    return new MyDbContext(options); 
}

Leave a Comment

404 Not Found

Not Found

The requested URL was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.