I’m trying to retrieve data from an entity and populate a viewModel property like this:
viewModel.Enrollments = db.Enrollments.Where(b => b.classDays == "Monday") && (db.Enrollments.Where(b => b.CourseID == courseID);
but I get a operator && cannot be applied to operands of type System.Linq.IQerable<> error. Can you help with a way to find all Monday class with the same ID?
I tried this: viewModel.Enrollments = db.Enrollments.Where(b => b.classDays == "Monday") but I get all Mondays courses but I want to limit them to a specific courseID.
Please help!
You need to examine your parentheses. This code won’t even compile:
In that code you’re trying to use
&&between two calls to.Where(), which return anIQueryable. You probably mean to use&&within the.Where()clause:Or perhaps append a second
.Where()clause:Note that
.Where()can be chained indefinitely, essentially resulting in applying each clause in turn in anANDfashion in the resulting query.