System.InvalidOperationException: Relational-specific methods can only be used when the context is using a relational database provider

Taufik Shaikh picture Taufik Shaikh · May 23, 2018 · Viewed 8.3k times · Source

System.InvalidOperationException:

Relational-specific methods can only be used when the context is using a relational database provider.

Getting the above mentioned error while using InMemoryDatabase for Test Case?

var msaContextOptions = new DbContextOptionsBuilder<MSA.DAL.MsaDbContext>()
           .UseInMemoryDatabase(databaseName: "Get results")
           .ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning))
           .Options;

Answer

Hemant Sakta picture Hemant Sakta · Jul 30, 2019

As mentioned by other people I found skipping DBMigration is the best option for now. I am running Database Migration when Database ProviderName is not InMemory.

if (context.Database.ProviderName != "Microsoft.EntityFrameworkCore.InMemory")
{
    context.Database.Migrate();
}