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;
Comparing with provider string is brittle - what if Microsoft changes to Microsoft.EntityFramework
as it moves away from Core!
I would recommend to use
if (!context.Database.IsInMemory())
{
context.Database.Migrate();
}
or
if (context.Database.IsRelational())
{
context.Database.Migrate();
}
we have EF-related code in a separate nuget package that doesn't include Microsoft.EntityFrameworkCore.InMemory
, therefore first option doesn't work for us.
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With