linq实现左连接

 var query = (
                        from a in station
                        join b in mic_data on a.ID equals b.ID into joinEmpDept
                        from x in joinEmpDept.DefaultIfEmpty()
                        join c in mic_data1 on a.ID equals c.ID into joinEmpDept2
                        from j in joinEmpDept2.DefaultIfEmpty()
                        select new
                        {
                            a.NAME,
                            x.NO2,
                            .......
                            AQIH = Math.Round((double)((x.AQI - j.AQI) / (j.AQI == 0 ? 1 : j.AQI) * 100), 2)
                        }
                        ).ToList();

加上null值判断

                            NO2 = x == null ? 0 : x.NO2,
                            SO2 = x == null ? 0 : x.SO2,
                            PM10 = x == null ? 0 : x.PM10,

......

【1】linq左连接参考https://www.cnblogs.com/yxys/p/5895372.html

【2】DefaultIfEmpty()方式输出的null值判断

         https://blog.csdn.net/lwjnumber/article/details/52032724

猜你喜欢

转载自blog.csdn.net/u010082526/article/details/84578683