I've created a brand new Project in .NET Core 3.1 and a query I am creating is generating a SQL query (viewed in SQL Server Profiler) that does not contain a where clause and instead reads in the entire table. Is there a way to pass in a predicate and have that incorporated into the SQL statement that is ultimately generated?
In the below function query1
is an IQueryable<Balance>
and query2
is an IEnumerable<Balance>
:
public int GetCount(Func<Balance, bool> predicate)
{
var query1 = (from b in _appContext.Balance
select b
);
var query2 = query1.Where(predicate);
var count = query2.Count();
return count;
}
Called like this:
GetCount(p => p.Email == 'test@gmail.com');