表格: [
查询模型:
...public string Keys { get; set; }
public int[] Cities { get; set; }
public int[] Sectors { get; set; }...
控制器:
public List<PostJob> SearchQuery(SearchFilterModel model)
{
var query = _postJobService.AsQueryable();
if (!string.IsNullOrWhiteSpace(model.Keys))
{
var keyWords = model.Keys.Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
query = query.Where(i => keyWords.Any(j => i.Title.Contains(j) || i.SeachTags.Contains(j)));
}
if (model.Cities.Length > 0)
{
query = query.Where(i => i.JobLocations.Any(j => model.Cities.Contains(j.CityId)));
}
if (model.Sectors.Length > 0)
{
query = query.Where(i => i.JobFeatures.Any(j => j.CategoryId == Startup.AppSettingsFeatures.Sector && model.Sectors.Contains(j.FeatureId)));
}
return query.ToList();
}
因此,它正在识别两个表之间的关系。我有很多变量可以过滤和搜索信息中的键,搜索标签(也许是信息)。postjob表将来可能会很大,因此我需要最好的方法来进行搜索和过滤查询。我研究了许多文档并编写了此代码。
如何改善大表的代码?
什么是最好的?
query1 = query.Where(i => i.JobLocations.Any(j => model.Cities.Contains(j.CityId)));
query2 = query.Where(i => model.Cities.Any(j => i.JobLocations.Select(k => k.CityId).Contains(j)));
什么是最有用的搜索字符串中的字符串数组的查询(例如Title /搜索标签,信息中的search / contains keyword [])