0

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?

2
  • 2
    Why can't you use && 3 times? Also, your ? true : false is pointless, any already returns true or false Commented Aug 15, 2011 at 13:20
  • Why can't you use the && operator three times? You might be able to do ".Where().Where().Where().Any()", but the two &&'s would be better. Commented Aug 15, 2011 at 13:21

2 Answers 2

1

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);
Sign up to request clarification or add additional context in comments.

Comments

1

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;

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.