我需要檢查列表中的元素是否包含值true。我米目前得到一個錯誤& &不能應用到bool或服務&&不能應用於布爾
在此condition & services.FirstOrDefault(p => p.IsPrimaryBusinessLine == true)
:
var services = serviceRepository
.GetServicesByRequestID(newReqeustViewModel.RequestID);
if (services != null &&
services.Count != 0 &&
services.FirstOrDefault(p => p.IsPrimaryBusinessLine == true))
服務
public class Service : BaseEntity
{
public int ServiceID { get; set; }
public int RequestID { get; set; }
public string BusinessLineCode { get; set; }
public string BusinessLine { get; set; }
public bool IsPrimaryBusinessLine { get; set; }
public int ContractLineSLAID { get; set; }
}
嘗試這樣'如果(服務= NULL && services.Count = 0 && services.Any (p => p.IsPrimaryBusinessLine))' – Nino
'services.FirstOrDefault(p => p.IsPrimaryBusinessLine == true)'返回'服務'實例。您需要再次比較一下''&&'操作符所需的'bool'實例。 –