Вместо того, чтобы создавать так много условий внутри запроса, сделайте это снаружи:
var query = _context.Students.Where(x => x.FacultetId == Facultet);
// filter by profession if there is some value
if (!string.IsNullOrempty(model.Profession))
{
query = query.Where(x => x.Profession.Contains(model.Profession));
}
// continue with the rest of the filters...
// and only then execute the query
var students = query.ToList();
Проверка на обнуляемость int
такая же.
Предполагая, SomeValue
является
public int? SomeValue;
тогда:
if (model.SomeValue != null)
{
query = query.Where(x => x.SomeValue == model.SomeValue);
}