private async Task PopulateDepartmentsDropDownList(object selectedDepartment = null) { IOrderedQueryable <Department> departments = from d in _context.Departments orderby d.Name select d; ViewBag.DepartmentId = new SelectList( await departments.AsNoTracking().ToListAsync(), "DepartmentId", "Name", selectedDepartment ); }
public IQueryable <FamilySearchResult> GetFamiliesByPersonNameSearch(string searchString, int maxResults = 20) { bool reversed; RockContext rockContext = new RockContext(); PersonService personService = new PersonService(rockContext); Guid homeAddressGuid = Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME.AsGuid(); // get list of people matching the search string IOrderedQueryable <Person> sortedPersonQry = personService .GetByFullNameOrdered(searchString, true, false, false, out reversed); var personResults = sortedPersonQry.AsNoTracking().ToList(); List <FamilySearchResult> familyResults = new List <FamilySearchResult>(); foreach (var person in personResults) { var families = personService.GetFamilies(person.Id) .Select(f => new FamilySearchResult { Id = f.Id, Name = f.Name, FamilyMembers = f.Members.ToList(), HomeLocation = f.GroupLocations .Where(l => l.GroupLocationTypeValue.Guid == homeAddressGuid) .OrderByDescending(l => l.IsMailingLocation) .Select(l => l.Location) .FirstOrDefault(), MainPhone = f.Members .OrderBy(m => m.GroupRole.Order) .ThenBy(m => m.Person.Gender) .FirstOrDefault() .Person.PhoneNumbers.OrderBy(p => p.NumberTypeValue.Order).FirstOrDefault() }) .ToList(); foreach (var family in families) { familyResults.Add(family); } } return(familyResults.DistinctBy(f => f.Id).AsQueryable()); }
/// <summary> /// 进行搜索 /// </summary> public virtual void DoSearch() { IOrderedQueryable <TModel> query = null; //根据搜索模式调用不同的函数 switch (SearcherMode) { case ListVMSearchModeEnum.Search: query = GetSearchQuery(); break; case ListVMSearchModeEnum.Export: query = GetExportQuery(); break; case ListVMSearchModeEnum.Batch: query = GetBatchQuery(); break; case ListVMSearchModeEnum.MasterDetail: query = GetMasterDetailsQuery(); break; case ListVMSearchModeEnum.CheckExport: query = GetCheckedExportQuery(); break; case ListVMSearchModeEnum.Selector: query = GetSelectorQuery(); break; default: query = GetSearchQuery(); break; } //如果设定了替换条件,则使用替换条件替换Query中的Where语句 if (ReplaceWhere != null) { var mod = new WhereReplaceModifier(ReplaceWhere); var newExp = mod.Modify(query.Expression); query = query.Provider.CreateQuery <TModel>(newExp) as IOrderedQueryable <TModel>; } if (string.IsNullOrEmpty(Searcher.SortInfo) == false) { var mod = new OrderReplaceModifier(Searcher.SortInfo); var newExp = mod.Modify(query.Expression); query = query.Provider.CreateQuery <TModel>(newExp) as IOrderedQueryable <TModel>; } if (typeof(TModel).IsSubclassOf(typeof(PersistPoco))) { var mod = new IsValidModifier(); var newExp = mod.Modify(query.Expression); query = query.Provider.CreateQuery <TModel>(newExp) as IOrderedQueryable <TModel>; } if (PassSearch == false) { //如果需要分页,则添加分页语句 if (NeedPage && Searcher.Limit != -1) { //获取返回数据的数量 var count = query.Count(); if (count < 0) { count = 0; } if (Searcher.Limit == 0) { Searcher.Limit = ConfigInfo.RPP; } //根据返回数据的数量,以及预先设定的每页行数来设定数据量和总页数 Searcher.Count = count; Searcher.PageCount = (int)Math.Ceiling((1.0 * Searcher.Count / Searcher.Limit)); if (Searcher.Page <= 0) { Searcher.Page = 1; } if (Searcher.PageCount > 0 && Searcher.Page > Searcher.PageCount) { Searcher.Page = Searcher.PageCount; } EntityList = query.Skip((Searcher.Page - 1) * Searcher.Limit).Take(Searcher.Limit).AsNoTracking().ToList(); } else //如果不需要分页则直接获取数据 { EntityList = query.AsNoTracking().ToList(); Searcher.Count = EntityList.Count(); Searcher.Limit = EntityList.Count(); Searcher.Page = 1; } } else { EntityList = query.AsNoTracking().ToList(); } IsSearched = true; //调用AfterDoSearch函数来处理自定义的后续操作 AfterDoSearcher(); }
public static IEnumerable <CarBrand> FindBrands(this IOrderedQueryable <CarBrand> carBrands) { IEnumerable <CarBrand> brands = carBrands.AsNoTracking(); return(brands); }