/// <summary> /// 根据市级区划ID反向查询省级区划 /// </summary> private void FindProvinceReverse() { var list = (from c in Citys let alias = c.Alias.Split(',').FirstOrDefault(_Address.Contains) let key = alias ?? c.Name let index = GetIndex(key) where index >= 0 orderby index select new { region = c, index, key }).ToList(); if (!list.Any()) { ReverseFromCounty(); return; } var city = list.First(); _City = city.region; _Province = Provinces.Single(p => p.ID == _City.ParentId); _Countys = Countys.Where(c => c.ParentId == _City.ID).ToList(); SetIndex(city.index, _City.Name, city.key); FindCounty(); }
/// <summary> /// 在市级区划范围内尝试通过镇级区划反向查询县级区划 /// </summary> private void FindCountyReverse() { var list = (from c in _Countys join t in Towns on c.ID equals t.ParentId let alias = t.Alias.Split(',').FirstOrDefault(_Address.Contains) let key = alias ?? t.Name let index = GetIndex(key) where index >= 0 orderby index select new { region = t, index, key }).ToList(); if (!list.Any()) { return; } var town = list.First(); _Town = town.region; _Index = town.index; _County = Countys.Single(c => c.ID == town.region.ParentId); }