Saturday, August 8, 2020

EntityFramework Core : Transaction execution issue when using In-Memory database

The EntityFramework In-Memory database does not support Transactions as of this writing. Therefore you might get the error: 

Error generated for warning 'Microsoft.EntityFrameworkCore.Database.Transaction.TransactionIgnoredWarning: Transactions are not supported by the in-memory store. See http://go.microsoft.com/fwlink/?LinkId=800142'. This exception can be suppressed or logged by passing event ID 'InMemoryEventId.TransactionIgnoredWarning' to the 'ConfigureWarnings' method in 'DbContext.OnConfiguring' or 'AddDbContext'.


To solve this issue, you need to ignore the Transaction Warning when EF is Configured.

 iWebHostBuilder.ConfigureServices(services =>
{
                   services.AddDbContext<IvitDbContext>(options =>
                {
                    options.UseInMemoryDatabase("InMemoryDb");
                    //In memory db does not support transactions. Hence ignore transaction warnings
                    options.ConfigureWarnings(x => x.Ignore(InMemoryEventId.TransactionIgnoredWarning));
                });
});


No comments:

Post a Comment