Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InMemory provider doesn't work when mixing enabling/disabling proxies #13165

Closed
genne opened this issue Aug 30, 2018 · 2 comments
Closed

InMemory provider doesn't work when mixing enabling/disabling proxies #13165

genne opened this issue Aug 30, 2018 · 2 comments

Comments

@genne
Copy link

genne commented Aug 30, 2018

If you add one entity to the database using proxies, and then try to query it with proxies disabled, you won't receive any data. It seems like enabling vs disabling proxies creates two separate databases.

Steps to reproduce

class MyContext : DbContext 
{
    private bool _useProxies;

    public MyContext (bool useProxies)
    {
        _useProxies = useProxies;
    }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseInMemoryDatabase("Test");
        optionsBuilder.UseLazyLoadingProxies(_useProxies);
    }

    public DbSet<MyEntity> MyEntities { get; set; }
}

var proxyContext = new MyContext(true);
proxyContext.MyEntities.Add(new MyEntity());
proxyContext.SaveChanges();

var nonProxyContext = new MyContext(false);
var entities = nonProxyContext.MyEntities.ToArray();
Assert.That(entities, Is.Not.Empty); // Will fail

Further technical details

EF Core version: 2.1.2
Database Provider: Microsoft.EntityFrameworkCore.InMemory
Operating system: Windows 10
IDE: Visual Studio 2017 15.8.1

@ajcvickers
Copy link
Member

@genne This is a manifestation of #9613 since model built for lazy-loading proxies is different than the one built for non-proxies, causing in this case a different service provider to be built. See PR #9692 for the way to force use of the same in-memory database database. See also #12895 which will allow proxy creation to be switched on and off without this side effect.

@genne
Copy link
Author

genne commented Aug 31, 2018

Ok great I see. Thanks for the reply!

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants