2011-09-26 85 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