Reputation: 6768
I have got a query which returns True or False, depending on the criteria set in the query:
bool eventVoucherUsed = getAllBookings.Any(r => r.EventID == booking.EventID && r.Voucher != null) ? true : false;
I want to modify the above query by adding one more check:
booking.VoucherStatus == True
But I can't use the And
operator three times. Is there any other alternative to achieve this?
Upvotes: 0
Views: 66
Reputation: 3441
Well if your example is accurate booking is something you already know so I can't see any reason too not just check that before even hitting the database:
bool eventVoucherUsed =
booking.VoucherStatus
? getAllBookings.Any(r => r.EventID == booking.EventID && r.Voucher != null)
: false;
Upvotes: 1
Reputation: 43067
I'm not sure what you mean by "cant use And operator three times". All that you need to do is add the condition to your predicate.
bool eventVoucherUsed =
getAllBookings.Any(r => r.EventID == booking.EventID
&& r.Voucher != null
&& booking.VoucherStatus == true);
Upvotes: 1