public IQueryable<JobLevelsWithJobCountViewModel> JobLevelsWithJobCountViewModels(string location = null)
{
return (from jl in _dbContext.JobLevels
from j in jl.Jobs
.Where(job => job.Company.ZipCode.MajorArea.Contains(location))
.Where(job => !job.IsDeleted && !job.IsPrivate)
group jl by jl.JobLevelId into g
select new JobLevelsWithJobCountViewModel
{
JobLevel = g.FirstOrDefault(),
JobCount = g.FirstOrDefault().Jobs.Count(j => !j.IsDeleted && !j.IsPrivate)
});
}
我不想添加此条件。其中(job =&gt; job.Company.ZipCode.MajorArea.Contains(location))如果location为null
答案 0 :(得分:0)
如果OR
为空,请使用短路location
运算符来传递条件:
.Where(job => location == null || job.Company.ZipCode.MajorArea.Contains(location))