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

多表关联
C# code

    var result = from s in stock
                         join r in report on s["ProductId"] equals r["ProductId"] into sr
                         join p in product on s["ProductId"].ToString().ToLower() equals p["ProductId"].ToString().ToLower() into rp
                        


看代码,不废话,这里s是主表,但是我现在又要关联1个表w,这个表里面有一个字段跟r表里面字段warehouseid关联,可是这里r不是主表,根本不能关联到,请问用什么办法管理这两个副表呢,本人小菜,希望原谅。


------解决方案--------------------
上面有个错
C# code

var result = from s in stock
              join r in report on s["ProductId"] equals r["ProductId"] into sr
              from srs in sr.DefaultIfEmpty()
               join p in product on s["ProductId"].ToString().ToLower() equals p["ProductId"].ToString().ToLower() into rp
              from rps in rp.DefaultIfEmpty()
              join w in w_table on srs.warehouseid equals w.ID into wr
              from wrs in wr.DefaultIfEmpty()