I'm writing this here, in the hope that someone has experienced this before and has a thorough answer to this problem.
We have a C# Web API that handles CRUD operations where we are using EF Core as our ORM to manipulate data.
From inspecting the SQL logs we can see that there are many select statements that are unfiltered (no where clause). That don't seem to be coming from the code base.
What is strange about this is some of the tables that are being called have no other references in the code other than being on the DBContext itself.
For example.
public class MyContext : DbContext{
public DbSet<MyDbSet> MyDBSet { get; set; }
}
This seems to periodically output a select statement on the table even if its not used in the code.
SELECT [m].[Id], [m].[Column1], [m].[Column2]
FROM [MyDBSet] AS [m]
The problem with this is, that some of these tables have large amounts of data in which I would like to avoid an unfiltered query.
From further inspection it seems that the order in which these unfiltered queries occur is the same order they are found on the DBContext.
Example 2
public class MyContext : DbContext{
public DbSet<MyDbSet> MyDBSet { get; set; }
public DbSet<MyDbSet2> MyDBSet2 { get; set; }
public DbSet<MyDbSet3> MyDBSet3 { get; set; }
}
SELECT [m].[Id], [m].[Column1], [m].[Column2]
FROM [MyDBSet] AS [m]
SELECT [m].[Id], [m].[Column1], [m].[Column2]
FROM [MyDBSet2] AS [m]
SELECT [m].[Id], [m].[Column1], [m].[Column2]
FROM [MyDBSet3] AS [m]
This happens even when the table is not read or referenced in the codebase, and there are no references to these tables that don't have a where clause.
My first assumption is that EF core is taking a snapshot of the table? Perhaps query caching or something similar?
I guess my question is, does anyone know what could be causing such odd behaviour and or is there something in EF core that is responsible.
NOTE - We are not using Lazy Loading Proxies package and are using eager loading throughout the application