// GET: Regions public IActionResult Index(bool isReadable, SortState sortOrder = SortState.NameAsc, string searchString = "") { IQueryable <Region> regions = _context.region.ToList().AsQueryable(); ViewData["NameSort"] = sortOrder == SortState.NameAsc ? SortState.NameDesc : SortState.NameAsc; ViewData["CurrentFilter"] = searchString; ViewData["isReadable"] = false; if (!string.IsNullOrEmpty(searchString)) { regions = regions.Where(s => s.name.StartsWith(searchString)); } regions = sortOrder switch { SortState.NameDesc => regions.OrderByDescending(s => s.name), _ => regions.OrderBy(s => s.name), }; if (isReadable == true) { ViewData["isReadable"] = true; CountryContext countryContext = new CountryContext(); var query = regions.Join( countryContext.country, regions => regions.country_id, country => country.country_id, (regions, country) => new FullRegion { region_id = regions.region_id, Country = country.name, Region = regions.name }); ViewData["Res"] = query.AsNoTracking().ToList(); return(View()); } return(View(regions.AsNoTracking().ToList())); }