2016-01-20 58 views
0

我想爲內部連接子句構建動態Linq to Sql查詢,其中內部連接將包括多個動態列進行連接。如何創建動態內部連接多個柱子

下面是在編譯時查詢,我需要動態acheive:

var source = lParent.GroupJoin(lChild, 
    p => new{ p.PID,p.CategoryId (These are dynamic columns)} 
    c => new{ c.PID,c.CategoryId (These are dynamic columns)} 
    (p, g) => new { Parent = p, Childs= g }) 

謝謝。

+0

你是什麼意思的「動態」?用戶是否可以確定要加入的列或要重新使用具有不同聯接的查詢?擁有動態連接子句似乎很奇怪。 –

回答

0

您可以使用下面的查詢進行內部連接。 使用GroupJoin來自this link的代碼。

source.AsQueryable() 
.GroupJoin(destination.AsQueryable(), 
      outer.ToString(), 
      inner.ToString(), 
      "new (outer as sources, group as destinations)") 
.SelectMany("destinations", "new(outer as sources, inner as destinations)");