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

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条回答 默认 最新

  • foomow
    茂大叔 2019-06-14 00:43
    已采纳
    exp = exp.And(a => AreaCodeList.Exists(x => a.AreaCode.StartsWith(x.Substring(0, AreaCode.Length))));
    
    点赞 评论

相关推荐