Bool在IQueryable

时间:2012-04-03 02:24:37

标签: c# linq entity-framework ado.net

我有以下错误

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。

3 个答案:

答案 0 :(得分:3)

.LastOrDefault仍将返回PatientsTelephoneFollowupDetail,正如错误所示,该值不是真值或假值。如果要检查项目是否存在,请使用.Any

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

答案 1 :(得分:0)

Where内的委托应该返回一个布尔值。

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

肯定不会是一个。

你到底想做什么?

答案 2 :(得分:0)

您应该使用.Select而不是.Where条款。