0

I have already searched in other questions for a solution, but didn't find it. So, my problem is the following: I have a page where the user can mount an expression. For example, if they want some professors with course 1 and course 2 then, they create an expression like this: (course 1 AND course 2) in the page.

But when I use EF, if I put the "AND", I get no professor... if I change to "OR" I get some professors with 1 or 2 and maybe one of then have two courses.

I need the professors who have always the two courses (course 1 AND course 2)

How can I accomplish this?

(If my explanation get too confusing, let me know, I'll try in a other way!)

Neeku
  • 3,646
  • 8
  • 33
  • 43

2 Answers2

0

I tried to understand your explanation, Try something as following and let usknow if is the logic you are looking for? or you want something other result.

from x in db.professors.Where(x => x. professorId == professorId && (x.courseid == 'course1' && x.ukat == 'course2'))
Disha
  • 392
  • 2
  • 7
0

Maybe:

var result = db.Professors.Where(p => 
    p.Cursos.Count(c => searchedCourses.Contains(c.CourseId)) == searchedCourses.Count());

This way you get all the professors, filter their courses to match that in the specified search, and get only the professors with the same amount of filtered courses and the searched ones.

RMalke
  • 4,048
  • 29
  • 42