question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for `UseInMemoryDatabase`?

See original GitHub issue

I haven’t set up a reproduction repo yet, but I think my issue is related to inheriting from AuditDbContext.

I get the following error when I switch my integration tests from SQLite to InMem:

    System.InvalidOperationException : No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.

My context looks like this:

    public partial class MyDbContext : AuditDbContext
    {

        public MyDbContext (
            DbContextOptions<MyDbContext > options)
            : base(options)
        {
        }

I AM using AddDbContext, as proved by the following:

               services.AddDbContext<MyDbContext>(options =>
                {
                    options
                        //.UseSqlite("Data Source=InMemoryDbForTesting.db") // WORKS!!!
                        .UseInMemoryDatabase(databaseName: "MyDbContextName") // DOESNT WORK!!!
                        .UseInternalServiceProvider(dbContextInternalServiceProvider);
                });

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
VictorioBerracommented, Mar 12, 2020

I believe my issue was the call to UseInternalServiceProvider.

0reactions
hisuwhcommented, Aug 9, 2020

It’s possible

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why can't I call the UseInMemoryDatabase method on ...
According to EF Core: Testing with InMemory reference, you need to add the Microsoft.EntityFrameworkCore.
Read more >
InMemoryDbContextOptionsExte...
Configures the context to connect to the legacy shared in-memory database. This method is obsolete. Use UseInMemoryDatabase(DbContextOptionsBuilder, String, ...
Read more >
EF Core In-Memory Database Provider
Install; Get Started; Supported Database Engines. This database provider allows Entity Framework Core to be used with an in-memory database.
Read more >
How to use EF Core as an in-memory database in ASP. ...
EF Core is a lightweight, open-source, extensible ORM (Object Relational Mapper) that supports several database providers including SQLite, ...
Read more >
Fix: DbContextOptionsBuilder Does not contain a definition for ...
... accessible extension method UseInMemoryDatabase accepting a first ... Level Concepts in ADF (Pipeline, Activities, Linked Service etc..).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found