首页新闻找找看学习计划

动态获取属性

0
悬赏园豆:5 [待解决问题]
 var PreGruop = from pre in presale
                           group pre by pre.UserID into dateGroup
                           select new
                           {
                               xl = dateGroup.Sum(x => x.XiaoLiang),
                               zt = dateGroup.Sum(x => x.ZhanTingXiaoLiang),
                               cd = dateGroup.Sum(x => x.ZhanTingXiaoLiang),
                               hy = dateGroup.Sum(x => x.CheDai),
                               ew = dateGroup.Sum(x => x.ErWang),

                               sx = dateGroup.Sum(x => x.XinCheShangXian),
                               jq = dateGroup.Sum(x => x.XinCheJiaoQiangXian),
                               bf = dateGroup.Sum(x => x.XinCheChangXianBaoFei),

                               userName = dateGroup.Select(x => x.User.Name)
                           };

例如上边一个查询 用EF 聚合 得到若干列

现在想根据 传入参数("列名") 从结果中 动态 获取相应的值 如何处理

例如原来 DataTble - DataRow["列名"] 

问题补充:

 利用反射技术 可以实现 ,这样是不是最好的?

v.GetType().GetProperty("xl").GetValue(v, null)

l25321937的主页 l25321937 | 初学一级 | 园豆:27
提问于:2013-10-04 12:27
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册