Linq to achieve three tables left join

Objective achieved:

    select id,name,jname,cname from userinfo u left join job j on u.job=j.jid left join city c on u.city=c.cid  多表left join

code show as below:

                        List = var (U in dc.userinfos from
                        the Join J dc.jobs ON u.job in the equals j.jid INTO j_join
                        from X in j_join.DefaultIfEmpty ()
                        the Join dc.cities ON u.city C in the equals c.cid INTO c_join
                        V in c_join.DefaultIfEmpty from ()
                        SELECT new new
                        {
                            ID = u.id,
                            name = u.name,
                            jname = x.jname,
                            CNAME = v.cname,
                           / * U1 = U, X = X1, V1 = V * / // Do not use the way the object because the object may be null then the object property will throw an exception
                        .}) ToList ();

Reproduced in: https: //www.cnblogs.com/simpleBlue3/p/10717487.html

Guess you like

Origin blog.csdn.net/weixin_34405925/article/details/93307548