Skip to content

InMemory provider queries on tracked entities (unlike SQLServer provider) #12945

@wizofaus

Description

@wizofaus

With the InMemory provider, if you modify the value of an entity returned by EF, then immediately query on it, the query successfully finds the entity.
However when using SQLServer it doesn't, as the change hasn't been committed to the database yet.

E.g.

 class MyContext : DbContext
 {
       internal DbSet<MyObject> Objects { get; set; }

       void Foo()
       {
              Objects.FirstOrDefault().Value = 42;
              Console.WriteLine($"Found: {Objects.FirstOrDefault(o => o.Value == 42) != null}");
       }
 }

Assuming your database contains at least one Object with a value field not equal to 42, then using InMemory, this prints out "Found: true", but using SQLServer, prints out "Found: false".

Adding "SaveChanges();" before performing the query causes the behaviour to be the same, but as it is this discrepancy hid a rather nasty bug in my server that didn't show up in any of the automated testing.

Metadata

Metadata

Assignees

Type

No fields configured for Bug.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions