Linq to Entity 的问题

在使用动态字段时,如果是对list进行linq查询,可以用反射来实现,如果是用Linq to Entity暂时没找到可以用反射的方法,但是可以用近似的SQL写。或者在逻辑层面解决问题。


public class PeopleCntorl
    {
        public Dictionary<string, IEnumerable<people>> Dic;
        public PeopleCntorl()
        {
            List<people> peoples = new List<people>() 
            {
                new people{ID=0, Name="Rose", Age=21 }, 
                new people{ID=1, Name="Jack", Age=23 },
                new people{ID=2,Name="Mike",Age=29}
            };

            Dic = new Dictionary<string, IEnumerable<people>>();  
            
            IEnumerable<people> people=from x in peoples
                                       select x.Name;
            IEnumerable<people> people2 = from x in peoples
                                         select x.Age;
            Dic.Add("1", people);
            Dic.Add("2", people2);
        }

        public IEnumerable<people> GetEnumerable(string name)
        {
            IEnumerable<people> iEnumerale=Dic[name];
            return iEnumerale;
        }
    }
此时如果要获取不同字段,只要修改Dictionary里面的表达式就行了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值