Filtering in Linq in MVC4
<p>My table structure is as follows</p>

<p><strong>Course</strong></p>

<pre><code>ID    CourseName     

1       PHP
2       WORDPRESS
</code></pre>

<p><strong>MainCourse</strong></p>

<pre><code>ID     MainCourseName
1       FoundationPhp
2       FoundationWordPress
3       Diploma
</code></pre>

<p><strong>SubCourse</strong></p>

<pre><code>ID       MainCourseID   CourseID
 1           1             1
 2           2             2
 3           3             1
 3           3             2 
</code></pre>

<p>I have a search scenario which should fetch the below result</p>

<p>When an user searches by <code>PHP</code> alone,he should get the following result</p>

<pre><code> MainCourseName    CourseCombination    
  FoundationPHP       PHP
  Diploma             PHP,WORDPRESS
</code></pre>

<p>When an user searches by <code>WORDPRESS</code> alone,he should get the following result</p>

<pre><code>  MainCourseName           CourseCombination    
  FoundationWordPress       WORDPRESS
  Diploma                   PHP,WORDPRESS
</code></pre>

<p>When an user searches by <code>PHP,WORDPRESS</code> ,he should get the following result.</p>

<pre><code>   MainCourseName           CourseCombination
    Diploma                    PHP,WORDPRESS  
</code></pre>

<p>NOTE:If there is any other combination that contains both <code>PHP &amp; WORDPRESS</code> that should be shown as well.Example of one such combination will be like <code>PHP,WORDPRESS,JAVA</code>.</p>

<p>I have tried the following method</p>

<pre><code>     List&lt;int&gt; CourseId={1,2}//means user searches by both PHP &amp; WORDPRESS
     var courseList = _db.SubCourses
                      .AsEnumerable()
                      .Where(mcd =&gt; courseId.Contains(mcd.Course.Id))
                      .Select(mc =&gt; new RegistraionVM.clsCourseCodeSearch
                       {
                          CourseCode = mc.MainCourse.MainCourseName,
                          CourseCombination = string.Join(",", mc.MainCourse.SubCourse
                                                                .Select(mcd =&gt; mcd.Course.Name))                     

                        }).Distinct().Take(5).ToList();
</code></pre>

<p>The above query returns the following result</p>

<pre><code>  MainCourseName        CourseCombination    
  FoundationPHP         PHP
  FoundationWordPress   WORDPRESS
  Diploma               PHP,WORDPRESS
</code></pre>

<p>Desired result is</p>

<pre><code>  MainCourseName        CourseCombination        
  Diploma               PHP,WORDPRESS
</code></pre>

<p>How can I acheive the above result</p>