½鹿True+ 2019-06-13 18:00 采纳率: 100%
浏览 774
已采纳

lambda表达式相关,将判断改写

如何能将如下代码里的判断用lambda表达式代替,主要是我图里框起来的部分,万分感谢

//获取当前登录用户授权的行政区划编码
            List<string> AreaCodeList = area.GetUserDistrictCode(AreaCode);

            if (string.IsNullOrEmpty(queryJson))
            {
                return this.BaseRepository("ground_report", "MySql").FindList(a => true, pagination).ToList();
            }
            else
            {
                Expression<Func<Grw_MonitorPointEntity, bool>> exp = a => true;
                if (HydGeoUnit1 != "") exp = exp.And(a => a.HydGeoUnit1.Contains(HydGeoUnit1));
                if (HydGeoUnit2 != "") exp = exp.And(a => a.HydGeoUnit2.Contains(HydGeoUnit2));
                if (InputValue != "") exp = exp.And(a => a.MonitorPointID.Contains(InputValue));
                exp = exp.And(a => a.Year == Year);
                if (AreaCode != "00")//非全国
                {
                    if (AreaCodeList != null)//授权的行政区划List不为空
                    {
                        if (AreaCodeList[0] != "000000")//非最高级别
                        {
                            if (AreaCodeList.Count > 1)
                            {
                                //不知道咋写
                            }
                            else
                            {
                                exp = exp.And(a => a.AreaCode.StartsWith(AreaCodeList[0].Substring(0, AreaCode.Length)));
                            }
                        }
                    }
                }
                    }
  • 写回答

1条回答 默认 最新

  • 茂大叔 2019-06-14 00:43
    关注
    exp = exp.And(a => AreaCodeList.Exists(x => a.AreaCode.StartsWith(x.Substring(0, AreaCode.Length))));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试