I am somewhat new to EF and .NET Core. I'm coming from the PHP Framework Laravel which have some similar logic for Models and Query building, but I can't seem to find the relevant documentation for what Im looking for.
I have a Model where I want to perform a query based on POST data from a form, and filter the outcome based on the input from the user.
In Laravel I was able to do this conditionally to build a query for a Model like so:
$projects = Project::when($request->year_from, function($query) use ($request){
$query->where('delivery_year', '>=', $request->year_from);
})
->when($request->year_to, function($query) use ($request){
$query->where('delivery_year', '<=', $request->year_to);
})->get();
Here I added where statements to the query if the request contained any data for that specific filter. Is there a similar solution to Query models in EF?
I started writing some code like this, but I clearly realized it to be a bad implementation, since I start by fetching the entire result set, before eliminating results:
var logs = context.Logs.All();
if( PostData.LogLevel != null )
{
var logs = logs.Where((log) => log.LogLevel == PostData.LogLevel);
}