将此linq代码转换为表达式

时间:2011-09-26 07:44:14

标签: c# linq

C#专家可以帮助我将这个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
                                };

谢谢!

1 个答案:

答案 0 :(得分: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;