First, let's look at the database, City, County fields, some of which have nulls, that is, null values.
The data we queried is as shown in the figure above, as long as there is null data in the city and county, the whole line of data is not displayed.
Solution:
Code at the beginning:
- rc.children = (from rp in db.RegionPlace
- join a in db.PlaceInfo on rp.Province equals a.PlaceID
- join b in db.PlaceInfo on rp.City equals b.PlaceID
- join c in db.PlaceInfo on rp.County equals c.PlaceID
- where rp.RegionID == r.RegionID
- select new RegionClass { RegionName = "", Province = a.PlaceName, City = b.PlaceName, County = c.PlaceName }).ToList();
Copy code
Modified code:
- rc.children = (from rp in db.RegionPlace
- join a in db.PlaceInfo on rp.Province equals a.PlaceID
- join b in db.PlaceInfo on rp.City equals b.PlaceID
- into btemp
- from bt in btemp.DefaultIfEmpty()
- join c in db.PlaceInfo on rp.County equals c.PlaceID
- into ctemp
- from ct in ctemp.DefaultIfEmpty()
- where rp.RegionID == r.RegionID
- select new RegionClass { RegionName = "", Province = a.PlaceName, City = bt.PlaceName == null ? "" : bt.PlaceName, County = ct.PlaceName == null ? "" : ct.PlaceName }).ToList();
Copy code
The data is displayed normally after modification! As shown in the figure below.
|