Why can’t I call the UseInMemoryDatabase method on DbContextOptionsBuilder?

According to EF Core: Testing with InMemory reference, you need to add the Microsoft.EntityFrameworkCore.InMemory package to use UseInMemoryDatabase() extension method with DbContextOptionsBuilder:

Install-Package Microsoft.EntityFrameworkCore.InMemory

Afterwards, you can follow example given in “Writing tests” section like this:

var options = new DbContextOptionsBuilder<ProductContext>().UseInMemoryDatabase(databaseName: "database_name").Options;

using (var context = new ProductContext(options))
{
    // add service here
}

Leave a Comment