is it posible to use operators with _context

Steven
Steven used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2014

Commented:
I think User is not an IEnumerable. You cannot use the method Any on it.

Author

Commented:
Maybe I should've written what I was trying to accomplish, I'm trying to check if a specific user is active.
thanks
Top Expert 2014

Commented:
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?
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

Author

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.'
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

Top Expert 2014

Commented:
Most probable cause of the problem

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial