0

I have these lines of code:

var check = (from search in db.CartItems
             where search.ItemID == ID && search.CartID == UCart.ID
             select search);

and when I want to check if the query return empty I use:

if (!check.Any())

but it throws error:

'!check.Any()' threw an exception of type 'System.NullReferenceException'

I check around but it seems that everyone is fine with Any() except me. I have checked using FirstOrDefault() but still got the same error.

Is there something wrong in my code?

Luiso
  • 4,173
  • 2
  • 37
  • 60

0 Answers0