morrisjdev / FileContextCore

FileContextCore is a "Database"-Provider for Entity Framework Core and adds the ability to store information in files instead of being limited to databases.
Apache License 2.0
169 stars 45 forks source link

DbContext Dispose not works #18

Closed superarchi closed 4 years ago

superarchi commented 4 years ago

After disposing of the first context, the second contains the same data.

Example:

using (var context = new Context())
{
    context.Users.Add(new User());
    context.SaveChanges();
}

Directory.Delete(Path.Combine(AppContext.BaseDirectory, "appdata"), true);

using (var context = new Context())
{
    var u1 = context.Users.First();
}

I expected exception here

morrisjdev commented 4 years ago

Hi. Sorry for the late reply.

You are right. This is because FileContext stores the data in memory after the initial load. It then writes everything back to disc if anything changes. The cache is shared between multiple instaces of the DbContext. This is reason for the discovered behavior.

Do you have any problems with that behavior?