我需要在foreach循环中使用Predicate Builder创建多个And
条件,但该谓词采用最新的And
条件。基本上,谓词应该包含And
条件的列表,而reportProfileid
包含条件的列表
var cpaclassids = FetchProductTypes(ids);
var temp = cpaclassids;
var query = (from x in partJoinTableRepository.GetPartJoinQuery()
join y in partRepository.GetPartsQuery() on x.PartId equals y.Id
join z in partProductTypeReposiotry.GetPartProductTypesQuery() on x.PartId equals z.PartId
where y.IsSkipped == 0 && (y.IsDisabled != "Y" || y.IsDisabled == null) && z.CreatedDate == x.CreatedDate
&& x.CreatedDate == Convert.ToDateTime(fromDate)
select x).Cast<PartJoinTable>();
var predicate = PredicateBuilder.True(query);
foreach (var item in reportProfilesids)
{
predicate = predicate.And(z => temp.Contains(z.ProductTypeId.ToString()));
}
var lst1 = query.AsQueryable().Where(predicate).Distinct().ToList();