Expression<Func<PartJoinTable, bool>> predicate = null; var query2 = query.Join(partJoinTableRepository.GetPartJoinQuery(), "x.PartID", "PartID", "inner" + row + "", null); foreach (var item1 in query) { list.Add(new PartJoinTable { ProductTypeId = item1.x.ProductTypeId, PartId = item1.x.PartId }); } predicate = PredicateBuilder.True(list.AsQueryable()); if (typeid=="3") { if (row == 0) { predicate1 = predicate1.And(z => cpaclassids.Contains(z.x.ProductTypeId.ToString())); } else { predicate = predicate.And(x => cpaclassids.Contains(x.ProductTypeId.ToString())); } } row++;}int lst1 = query.Where(predicate).Select(x => x).Distinct().ToList().Count();無法從“System.Linq.Expressions.Expression>”轉換為“System.Func<, bool>”我無法檢索結果,因為它在我聲明變量時顯示上述錯誤 Expression<Func<PartJoinTable, bool>> predicate = null;
2 回答

長風秋雁
TA貢獻1757條經驗 獲得超7個贊
回答
表達式>謂詞=空;在 where 條件(query.Where(謂詞))中引發(fā)錯誤
是
if (predicate != null)
query = query.Where(predicate);
int lst1 = query.Distinct().Count();
where僅當它存在時才添加子句。使用.ToList()之前.Count()你伸出的每一行從數(shù)據(jù)庫到內存中。

繁星淼淼
TA貢獻1775條經驗 獲得超11個贊
您可以使用?
-編寫,它可以節(jié)省以下問題:if (predicate != null)
這是完整的代碼:
int lst1 = query.Where(predicate)?.Select(x => x)?.Distinct()?.ToList()?.Count;
你只能寫:Count
- 類中的屬性List
- 2 回答
- 0 關注
- 233 瀏覽
添加回答
舉報
0/150
提交
取消