日期:2014-05-20  浏览次数:20833 次

多表多条件联合查询
现有2表2条件联合查询

var query = from o in _context.Orders
                        //join c in _context.Customers on o.CustomerId equals c.CustomerId
                        join c in _context.Customers
                        on new { o.CustomerId, o.FromPT }
                        equals new { c.CustomerId, c.FromPT }
                        into s
                        from oc in s.DefaultIfEmpty()

想再加一个表
join risk in _context.OrderRiskLevel
 on new { o.OrderId , o.FromPT }
 equals new { risk.OrderId,risk.FromPT }

请问下怎么加上去
------解决方案--------------------
本帖最后由 q107770540 于 2013-12-12 22:28:48 编辑
那就加呗:

       var query = from o in _context.Orders 
                        join c in _context.Customers
                        on new { o.CustomerId, o.FromPT }
                        equals new { c.CustomerId, c.FromPT }  into s
                        from oc in s.DefaultIfEmpty()
            join risk in _context.OrderRiskLevel
              on new { o.OrderId , o.FromPT }
              equals new { risk.OrderId,risk.FromPT } into t
                        from risk in t.DefaultIfEmpty()
                        select o;