LINQ 多表关联(inner join,left join)

   var query = from t1 in dt.AsEnumerable()
                        join t2 in dt2.AsEnumerable()
                        on t1.Field("Addressid") equals t2.Field("Addressid") into tmp
                        join t3 in dt3.AsEnumerable()
                         on t1.Field("userid") equals t3.Field("userid")
                        from t in tmp.DefaultIfEmpty()
                        orderby t1.Field("insertdate") descending
                        select new
                        {
                            Name = t1.Field("Name"),
                            RealName = (t == null) ? string.Empty : t.Field("RealName"),
                            nickname = t3.Field("nickname")
                        };

 

 

左链接或右链接,使用DefaultIfEmpty()语法,采用些语法前需要用到into语法

你可能感兴趣的:(LINQ 多表关联(inner join,left join))