title: Querying n:m-Relationships with LINQ
body: <p>I got a n:m-Relationship with these three tables:</p>
  
  <p><img src="https://i.stack.imgur.com/L5DVS.png" alt="Database Model"></p>
  
  <p>Now I want to query all <code>Activities</code>, that have a list of selected <code>Characteristics</code> attached.</p>
  
  <p>My query:</p>
  
  <pre><code>e.QueryableSource = _dataContext.Activities.Where(ac =&gt; 
                  ac.UserId == _userId &amp;&amp; 
                  ac.ResubmissionDate &lt;= EntityFunctions.TruncateTime(_to) &amp;&amp; 
                  ac.Priority &lt;= (int)_prio &amp;&amp; 
                  ac.CompletedDate == null &amp;&amp; 
                  ac.Characteristics.Contains(CharacFilter));
  </code></pre>
  
  <p>That sadly doesn't work, as <code>ac.Characteristics.Contains()</code> expects items of type <code>ActivityCharacteristics</code>, and not a type of <code>Characteristic</code></p>
  
  <p>How can I achieve that?</p>
  
  <p>A side node: I don't want an exclusive filtering, say when I specify three characteristics in <code>CharacFilter</code>, I want to query every activity that may have one of these three characteristics (not necessarily all of them) attached.</p>
  
  <p>Edit:
  <code>CharacFilter</code> is a <code>private IEnumerable&lt;int&gt; CharacFilter { get; set; }</code> 
  It is being filled from a view where I select those characteristics and hold them in the View-Variable <code>public List&lt;Characteristic&gt; SelectedCharacteristics { get; set; }</code></p>
  
  <p>My assignment:</p>
  
  <pre><code>        var view = new AssignCharacteristicsView();
          view.ShowDialog();
  
          if (view.SelectedCharacteristics != null)
          {
              CharacFilter = view.SelectedCharacteristics.Select(cf =&gt; cf.Id);
          }
  </code></pre>
  
  <p>`</p>