Skip to content

Remove the in-memory provider #18457

Closed as not planned
Closed as not planned

Description

@ajcvickers

Note: the decision to do or not do this has not been made. Feedback is appreciated.

While the in-memory provider is marketed as "for testing" I think that is somewhat misleading. Its actual main value is as a simple back-end for all our internal non-provider-specific tests.

When we started EF Core, it seemed like it would also be useful for testing applications. This can work with appropriately factored test code and a good understanding of where the provider behavior is different. However, I haven't recommended this for many years, and I don't think anyone else on the team would recommend it either. The main reason is that it's too easy to get caught out by differences in provider behavior, and therefore not realize that the behavior of your test is different from the behavior in production. This can be mitigated by using a provider that is closer to what is being used in production--for example, SQLite. However, the only way to know if something really works is to test with the same code that is running in production.

So, if the only real, non-pit-of-failure approach is to not use the in-memory provider for testing, then maybe we shouldn't ship in 5.0?

On the other hand, it can work for those that understand the limitations, and testing isn't literally the only use for the in-memory provider, even though it is by far (e.g. 99ppfa) the most common.

Activity

  1. added this to the Backlog milestone on Oct 18, 2019
  2. gfoidl commented on Oct 18, 2019

    @gfoidl
    Member

    I agree with the rationale. But (as user of in-memory provider*) I'd like to see it in 5.0.
    To mitigate the concerns about wrong use, one could either

    • put more emphasis of "the dangers" in the documentation -- the behavior is quite well noted, but can be easily overlooked
    • remove in-memory from the documentation -- so "no" new user will catch it, whilst anyone who is aware of in-memory can still use it

    Of course if the cost for maintaining in-memory is too high, it may be better to just remove it.
    But then there's still the old nuget-packages, old documenation that doesn't prevent someone from using it (with more or less success...).


    * for tests where no relations, etc. are involved -- just simple inserts, reads, etc. It is easy to setup and reasonable fast for unit-tests as opposed to SQLite or SQL Server. In production the latter is used, so there are -- of course -- tests for more complex scenarios that run against real SQL Server.

  3. ErikEJ commented on Oct 19, 2019

    @ErikEJ
    Contributor

    I think it is the right thing to do! We are using Inmemory for our unit testing our micro services, but could just as easily use SQL LocalDB, in fact we already do this in a service where we use SQL Graph.

    Always using SQL LocalDB would give us much more confidence in our unit tests, and minimize the amount of "Swagger UI" or integration tests we need to run.

    It also seems like you spend a large amount of time making the Inmemory provider work with new features, time which could be well spent elsewhere.

  4. bachratyg commented on Oct 20, 2019

    @bachratyg

    Some feedback first. We've been using a custom provider on top of EF6 that mimicks the quirks of a particular version of Oracle while using an in-memory store. The setup is simple: get the DbCommandTree from EF and instead of generating SQL command text interpret it over the in-mem storage. This gives us a huge productivity boost since we could easily detect problems like unsupported query functions (collation mismatch, outer apply, clob vs varchar operations, etc), expressions that EF would not compile and test basic correctness like constraint checks and foreign keys. Even though it's not particularly optimized we can still run hundreds of tests in mere seconds while spinning up an Oracle test database would literally take minutes, not to mention the overhead of maintaining specific versions.

    I'm looking for something similar on top of EFCore. Would this be a good use case going forward for the in-memory provider (assuming it does not get axed)? Or would it be better to build it on top of the relational provider base? I'm not sure where to start, any pointers are welcome.

  5. kirnosenko commented on Oct 20, 2019

    @kirnosenko

    It would be a pity to lose such a great feature. In-memory is much better for testing than localdb. It is faster and allows isolation testing when I can push partially initialized entities into store.

  6. roji commented on Oct 21, 2019

    @roji
    Member

    For anyone commenting here, consider that the Sqlite in-memory testing option does exist as an alternative to InMemory. In cases where spinning up the actual database is too costly (e.g. Oracle), Sqlite provides a very high level of relational features (e.g. transactions) while still being extremely easy to set up and fast.

  7. stefannikolei commented on Oct 21, 2019

    @stefannikolei
    Contributor

    Having the InMemory provider makes it really easy for some tasks. In my case I am using it mostly just for local development in the case I have hangfire.io in the app. So I do not have to spin up an sql database (It would not be too hard but in memory is just too easy in that case)

    The other are the tests. Here I would not be concerned to switch to sqlite.

  8. AndriySvyryd commented on Oct 22, 2019

    @AndriySvyryd
    Member

    Also note that even if we no longer ship the in-memory provider, it is still open source. So anyone that really needs it can create a fork and publish it in a different package. This would likely result in more features being added to the provider by the community as the EF team usually prioritizes them lower than the features for other providers.

  9. ErikEJ commented on Oct 22, 2019

    @ErikEJ
    Contributor

    @AndriySvyryd So "remove" just means "do not publish on NuGet" ?

  10. roji commented on Oct 22, 2019

    @roji
    Member

    @ErikEJ it would mean that we would no longer be maintaining it, making sure it's compatible with latest EF Core versions, etc. The community would have to be responsible for things like adapting InMemory for any provider-facing breaking changes.

  11. stephenjeffreywhite commented on Oct 22, 2019

    @stephenjeffreywhite

    I never really use the in memory provider, since it doesn't behave like a true DB. As @roji pointed out, Sqlite is an alternative, and a better one, IMO. Suffice to say, I opted to use SQLite in memory for my tests instead of bothering with the one that is the subject of this issue. You won't see any complaints from anyone on my team if you decide to go through with this change.

  12. jespersh commented on Nov 14, 2019

    @jespersh

    I found that the InMemory provider gave me more issues than it solved and I ended up today going towards the SQLite provider for testing. But even then the SQLite provider gave one glaring issue when running in memory too and that was I couldn't run EnsureDeleted between each test.

    What I'd suggest is to point the InMemory provider to the SQLite in a "in memory" configuration and a EnsureCreated run (maybe?). It might give more value for some this way looking for a quick setup before running into caveats.

  13. 27 remaining items

  14. removed this from the Backlog milestone on Apr 17, 2020
  15. ajcvickers commented on Apr 17, 2020

    @ajcvickers
    ContributorAuthor

    TL;DR:

    • We are not going to remove the in-memory provider.
    • We are creating updated testing guidance.
    • We may de-emphasize features in the in-memory provider, but this will be somewhat based on demand for and feedback on these features.

    We really appreciate the great discussion that this issue has generated. I think it is pretty clear that while to some people the in-memory provider is not needed, to others it is essential to their development flow. Also, telemetry from VS and VS Code indicates that many developers are referencing the in-memory provider assembly/NuGet package. Therefore, we are not going to remove the in-memory provider.

    We have already begun updating our testing guidance to emphasize the trade-offs involved in different testing approaches. We're also going to update this guidance with some samples of different techniques for using the in-memory provider and other providers effectively in tests.

    Some features in the in-memory provider (especially query translations) can be very expensive relative to the value they bring. We may de-emphasize these kinds of fixes to free up more resources for other areas. However, we will also consider feedback and will still consider making fixes for things where the demand is high.

  16. hauntingEcho commented on Mar 30, 2021

    @hauntingEcho

    For anyone else reaching this topic while investigating the in-memory database for testing - there is a dotnet implementation of Java's fantastic TestContainers library, which manages per-test docker containers for your database (or anything else you're integrating with that can be dockerized) and will keep the behavior closer to your database of choice.

  17. sebastianstudniczek commented on Dec 12, 2022

    @sebastianstudniczek

    Some features in the in-memory provider (especially query translations) can be very expensive relative to the value they bring. We may de-emphasize these kinds of fixes to free up more resources for other areas. However, we will also con

    Would you use it in unit testing?

  18. removed their assignment
    on Sep 1, 2024
  19. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions