Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are talking about EntityFramework (Linq to entities) right? If so, Include() is a Method of Linq To Entities to include a sub-relation in the result set. I think you should place the Where() outside of the Inlcude().</p> <p>On <a href="https://stackoverflow.com/questions/3356541/entity-framework-linq-query-include-multiple-children-entities">this topic</a> you'll find some examples on how to use the Include() method.</p> <p>So I suggest to add the Include()'s first to include the relations "Members" and "Leaders" and then apply your Where-Statement (can be done with one Where()).</p> <pre><code>return db.Teams .Include("Team.Members") .Include("Team.Leaders") .Where(t =&gt; string.IsNullOrWhitespace(t.Members.Experience) ... ) </code></pre> <p>What is unclear to me is your where criteria and your use-case at all as you are talking of getting a list of Teams with Leaders and Members. May above example will return a list of Teams that match the Where() statement. You can look though it and within that loop you can list its members and leaders - if that is the use-case.</p> <p>An alternative is something like this:</p> <pre><code>return db.Members .Where(m =&gt; string.IsNullOrWhitespace(m.Experience)) .GroupBy(m =&gt; m.Team) </code></pre> <p>This get you a list of members with no experience grouped by Team. You can loop the groups (Teams) and within on its members. If you like to get each team only once you can add a Distinct(m => m.Team) at the end.</p> <p>Hope this helps. If you need some more detailed code samples it would help to understand your requirements better. So maybe you can say a few more words on what you expect from the query.</p> <p><strong>Update:</strong></p> <p>Just read our edits which sound interesting. I don't think you can do this all in one Linq-To-Entities statement. Personally I would do that on the getters of the properties Members and Leaders which do their own query (as a read-only property). To get performance for huge data amount I would even do it with SQL-views on the DB itself. But this depends a little on the context the "Members" and "Leaders" are used (high frequent etc).</p> <p><strong>Update 2:</strong></p> <p>Using a single query to get a table of teams with sublists for members and leaders I would do a query on "Programmers" and group them nested by Team and Experience. The result is then a list of groups (=Teams) with Groups (Experienced/Non-experience) with Programmers in it. The final table then can be build with three nested foreach-Statements. See <a href="http://code.msdn.microsoft.com/LINQ-to-DataSets-Grouping-c62703ea" rel="nofollow noreferrer">here</a> for some grouping examples (see the example "GroupBy - Nested"). </p>
 

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