Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've been planning on writing <a href="http://blogs.msdn.com/alexj/archive/2009/03/26/index-of-tips.aspx" rel="noreferrer">a tip</a> on this but your question beat me to the punch.</p> <p>Assuming a <code>WorkItem</code> has many <code>WorkItemNotes</code></p> <p>you can do this:</p> <pre><code>var intermediary = (from item in ctx.WorkItems from note in item.Notes where note.SomeProp == SomeValue select new {item, note}).AsEnumerable(); </code></pre> <p>This produces an anonymous element for each <code>WorkItemNote</code> that matches, and holds the corresponding <code>WorkItem</code> too.</p> <p>EF identity resolution insures that the same <code>WorkItem</code> (by reference) is returned multiple times if it has multiple <code>WorkItemNotes</code> that match the criteria.</p> <p>I assume that next you want to just get back to just the <code>WorkItems</code>, like this:</p> <pre><code>var workItems = intermediary.Select(x =&gt; x.item).Distinct().ToList(); </code></pre> <p>Then if you now do this:</p> <pre><code>foreach(var workItem in workItems) { Console.WriteLine(workItem.Notes.Count) } </code></pre> <p>You will see that <code>WorkItemNotes</code> that match the original filter have been added to the Notes collection of each <code>workItem</code>. </p> <p>This is because of something called Relationship Fixup.</p> <p>I.e. this gives you what you want conditional include.</p> <p>Hope this helps</p> <p><a href="http://twitter.com/adjames" rel="noreferrer">Alex</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload