Closed JonPSmith closed 2 years ago
@JonPSmith Query filters impact what comes from the database--i.e. queries--but does not impact how entities that are already tracked are handled. If you have a tracked entity--for example, after running a query with no filter--then you can work with it in the normal way. This is useful when you're dealing with some code that, for example, needs to look at entities that have been soft-deleted.
Thanks. I wrongly assumed that Find did NOT use the QueryFilter. Thank you for pointing out my mistake.
I am having trouble with QueryFilter interacting with
Find
. I expected theFind
method to find an entity even if it was filtered out by the query filter, but it doesn't. It is also inconsistent, in that if I read in the item to find as a tracked entity first, then it finds it.This seems so basic that I think it must be my problem, but I can't find anything I have done that explains that. Please could you look at it.
Steps to reproduce
Entity class
My DbContext
My unit test that fails on the test for
ShouldNotBeNull
Another test where I load the entity before calling Find. This unit test passes
PS. The unit tests use Sqlite, but it also goes wrong the the actual application which uses SQL Server.
Further technical details
EF Core version: netcoreapp2.1 - (dotnet --version says 2.1.401) Database Provider: (e.g. Microsoft.EntityFrameworkCore.Sqlite 2.1.3) Operating system: IDE: (e.g. Visual Studio 2017 15.4)