½鹿True+ 2019-06-13 18:00 采纳率: 0%
浏览 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))));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?