动态组合lambda 表达式

时间:2022-02-21 19:04:28
 //记录实体集合—动态组合lambda 表达式
                    Expression<Func<AdEntity, bool>> thirdWhere =
                        p => p.Observer.Split(',').Contains(ortableEntity.CompanyAdtId.ToString()) &&
                             p.AdStartDate <= commonProperty.SystemDateTime &&
                             p.ThirdAdId != ortableEntity.ThirdAdId;
                    //质量管理检查记录 动态组合lambda 表达式
                    Expression<Func<CheckEntity, bool>> checkWhere =
                        p => p.CheckGroupPerson.Split(',').Contains(ortableEntity.CompanyAdtId.ToString()) &&
                             p.CheckStartDate <= commonProperty.SystemDateTime;
                    //判断是否添加开始日期的校验
                    if (orTableWorking != null)
                    {
                        Expression<Func<AdEntity, bool>> starttWhere = p => p.AdStartDate >= orTableWorking.ParenORTable.ReportDate;
                        var invokedExpr = Expression.Invoke(starttWhere, thirdWhere.Parameters);
                        thirdWhere = Expression.Lambda<Func<AdEntity, bool>>
                            (Expression.And(thirdWhere.Body, invokedExpr), thirdWhere.Parameters);

                        Expression<Func<CheckEntity, bool>> startcWhere = p => p.CheckStartDate >= orTableWorking.ParenORTable.ReportDate;
                        invokedExpr = Expression.Invoke(startcWhere, checkWhere.Parameters);
                        checkWhere = Expression.Lambda<Func<CheckEntity, bool>>
                            (Expression.And(checkWhere.Body, invokedExpr), checkWhere.Parameters);
                        strOrTableWorking = orTableWorking.WorkingExperience + "\n";
                    }