Bool in IQueryable

本文关键字:IQueryable in Bool | 更新日期: 2023-09-27 18:29:59

我有以下错误

Error   1   Cannot implicitly convert type 'LightSwitchApplication.PatientsTelephoneFollowupDetail' to 'bool'   
Error   2   Cannot convert lambda expression to delegate type 'System.Func<LightSwitchApplication.PatientsTelephoneFollowupDetail,int,bool>' because some of the return types in the block are not implicitly convertible to the delegate return type

代码是

partial void StatusCallBackRequired_PreprocessQuery(ref IQueryable<PatientsTelephoneFollowupDetail> query)
{
   query = query.Where(p=> p.PatientsMasterItem.PatientsTelephoneFollowupDetail.LastOrDefault(c => c.Status == "7" ));
}

我想返回上次电话状态为7的患者记录。

Bool in IQueryable

.LastOrDefault仍将返回一个PatientsTelephoneFollowupDetail,正如错误所示,它不是true或false值。如果您想检查物品的存在,请使用.Any:

query = query.Where(p => p.PatientsMasterItem.PatientsTelephoneFollowupDetail.Any(c => c.Status == "7"));

Where内部的委托应返回布尔值。

p => p.PatientsMasterItem.PatientsTelephoneFollowupDetail.LastOrDefault(c => c.Status == "7" )

肯定不会是一个。

你到底想做什么?

您应该使用.Select,而不是.Where子句。