This article is a mirror article of machine translation, please click here to jump to the original article.

View: 23858|Reply: 0

[Source] Regarding the workaround for the Linq field to be null and not showing data

[Copy link]
Posted on 9/3/2015 11:44:57 PM | | | |

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:


  1. rc.children = (from rp in db.RegionPlace
  2.                                    join a in db.PlaceInfo on rp.Province equals a.PlaceID
  3.                                    join b in db.PlaceInfo on rp.City equals b.PlaceID
  4.                                    join c in db.PlaceInfo on rp.County equals c.PlaceID
  5.                                    where rp.RegionID == r.RegionID
  6.                                    select new RegionClass { RegionName = "", Province = a.PlaceName, City = b.PlaceName, County = c.PlaceName }).ToList();
Copy code


Modified code:

  1. rc.children = (from rp in db.RegionPlace
  2.                                    join a in db.PlaceInfo on rp.Province equals a.PlaceID
  3.                                    join b in db.PlaceInfo on rp.City equals b.PlaceID
  4.                                    into btemp
  5.                                    from bt in btemp.DefaultIfEmpty()
  6.                                    join c in db.PlaceInfo on rp.County equals c.PlaceID
  7.                                    into ctemp
  8.                                    from ct in ctemp.DefaultIfEmpty()
  9.                                    where rp.RegionID == r.RegionID
  10.                                    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.







Previous:The 1:1 ratio is completely imitated by the source code transfer of the WeChat APP project
Next:c# parse json strings into List collections
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com