is it posible to use operators with _context

good afternoon,
I was wondering if it is posible to use operators like OR/AND as follow in asp.net

 if (_context.User.Any(ac => ac.Id.Equals(23) && ac.Active.Equals(1)))

Open in new window


or what is the right way of doing something similar to that.

I appreciate your help thanks.
LVL 1
StevenAsked:
Who is Participating?
 
Snarf0001Commented:
If it's typical code, I'm assuming "Active" on the database is actually a bit flag.  In which case even though it's 0 or 1 on the db, it maps to true / false as a bool on the data context.

if (_context.User.Any(ac => ac.Id == 23 && ac.Active == true))

Open in new window

1
 
louisfrCommented:
I think User is not an IEnumerable. You cannot use the method Any on it.
0
 
StevenAuthor Commented:
Maybe I should've written what I was trying to accomplish, I'm trying to check if a specific user is active.
thanks
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
louisfrCommented:
My last comment was just a thought I had when reading your code and I forgot to actually answer the question.
You can use boolean operators in asp.net. Are you getting an error when you use them?
0
 
StevenAuthor Commented:
Im new to MVC, so im not sure if what I was doing was posible, this is the error I get System.ArgumentException: 'DbComparisonExpression requires arguments with comparable types.'
0
 
louisfrCommented:
Most probable cause of the problem
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.