2011-09-26 86 views
0

C#專家能幫助我將此linq代碼轉換爲表達式樹嗎?將此linq代碼轉換爲表達式

var settingViewModels = from l in settingsByEnvironment["Localhost"] 
           from d in settingsByEnvironment["Dev"] 
           from p in settingsByEnvironment["Prod"] 
           where l.Key == d.Key && p.Key == d.Key 
           select new MyKeyValue 
           { 
            Key = p.Key, 
            LocalhostValue = l.Value, 
            DevValue = d.Value, 
            ProdValue = p.Value 
           }; 

謝謝!

+0

嘗試使用http://msdn.microsoft.com/en-us/library/bb397951.aspx – Nahum

回答

4
var settingViewModels = from l in settingsByEnvironment["Localhost"].AsQueryable() 
         from d in settingsByEnvironment["Dev"].AsQueryable() 
         from p in settingsByEnvironment["Prod"].AsQueryable() 
         where l.Key == d.Key && p.Key == d.Key 
         select new MyKeyValue 
         { 
          Key = p.Key, 
          LocalhostValue = l.Value, 
          DevValue = d.Value, 
          ProdValue = p.Value 
         }; 

var expression = settingsViewModels.Expression; 
+0

+1不錯的:)) –

+0

那裏是我的settingsViewModels變量沒有Expression屬性。我應該參考什麼? – Gui

+0

是否添加了.AsQueryable()? – jzm