2010-09-05 217 views
1

我實際上不確定這是否完全是左連接;我不是SQL的專家。我有以下的Linq查詢:左加入Linq?

 var title = dataSet.Tables["title"].AsEnumerable(); 
     var author = dataSet.Tables["author"].AsEnumerable(); 
     var review = dataSet.Tables["review"].AsEnumerable(); 

     var results = from t in title 
         join a in author on t["Url"] equals a["Url"] 
         join r in review on t["Url"] equals r["Url"] 
         select new { 
          tText = t["InnerText"], 
          aText = a["InnerText"], 
          rText = r["InnerText"] 
         }; 

我的問題是,有時存在的「審覈」列中沒有匹配的評論,但我還是想拿到冠軍,並在我的結果筆者。我怎樣才能做到這一點?

回答

0

確定這個工作,不知道爲什麼,但:

 var title = dataSet.Tables["title"].AsEnumerable(); 
     var author = dataSet.Tables["author"].AsEnumerable(); 
     var review = dataSet.Tables["review"].AsEnumerable(); 

     var results = from t in title 
         join a in author on t["Url"] equals a["Url"] 
         join r in review on t["Url"] equals r["Url"] into g 
         from r in g.DefaultIfEmpty() 
         select new { 
          tText = t["InnerText"], 
          aText = a["InnerText"], 
          rText = r != null? r["InnerText"]: "" 
         };