You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
InMemory provider queries on tracked entities (unlike SQLServer provider) #12945
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.
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.
There's at least 3 different ways in which In-Memory provider works differently to the SQL-server provider. I'm happy to contribute a fix if there's nobody else working on it.
Note for triage: I was able to reproduce the case above. It looks like the in-memory query provider is doing identity resolution to the tracked entity before evaluating the predicate.
@david-waterworth@wizofaus The in-memory database will never behave exactly like SQL Server, or indeed any other relational database. However, we are tracking some issues to add additional functionality--for example, #6872
Sure, I'd never expect it to behave exactly the same, and indeed previous In-Memory DbSet libraries for EF 6 (.net Framework) had the same problem (or even worse - no distinction at all between tracked entity data and persisted data). But the fact that "real" databases query against the underlying data rather than current tracked entities would seem to be a useful behaviour to emulate.
changed the title [-]InMemory provider doesn't work the same way SQLServer[/-][+]InMemory provider doesn't work the same as SQLServer[/+]on Aug 9, 2018
changed the title [-]InMemory provider doesn't work the same as SQLServer[/-][+]InMemory provider queries on tracked entities (unlike SQLServer provider)[/+]on Aug 9, 2018
Activity
wizofaus commentedon Aug 9, 2018
There's at least 3 different ways in which In-Memory provider works differently to the SQL-server provider. I'm happy to contribute a fix if there's nobody else working on it.
ErikEJ commentedon Aug 9, 2018
@wizofaus Have you read this? https://docs.microsoft.com/en-us/ef/core/miscellaneous/testing/in-memory
ajcvickers commentedon Aug 9, 2018
Note for triage: I was able to reproduce the case above. It looks like the in-memory query provider is doing identity resolution to the tracked entity before evaluating the predicate.
@david-waterworth @wizofaus The in-memory database will never behave exactly like SQL Server, or indeed any other relational database. However, we are tracking some issues to add additional functionality--for example, #6872
wizofaus commentedon Aug 9, 2018
Sure, I'd never expect it to behave exactly the same, and indeed previous In-Memory DbSet libraries for EF 6 (.net Framework) had the same problem (or even worse - no distinction at all between tracked entity data and persisted data). But the fact that "real" databases query against the underlying data rather than current tracked entities would seem to be a useful behaviour to emulate.
[-]InMemory provider doesn't work the same way SQLServer[/-][+]InMemory provider doesn't work the same as SQLServer[/+][-]InMemory provider doesn't work the same as SQLServer[/-][+]InMemory provider queries on tracked entities (unlike SQLServer provider)[/+]ajcvickers commentedon Aug 9, 2018
@wizofaus The case you reported above is a bug. In-memory queries are made against the in-memory database, not the tracked entity instances.
5 remaining items
smitpatel commentedon Dec 7, 2019
InMemory is working same as SqlServer in 3.1 release. We don't track against tracked entities anymore.