title: Entity Framework Query Result as List of Complex Object
body: <p>First of all I'm newbie at Back-End. Forgive me if that is stupid question. I was searching for the answer almost for 3 days. I learned a lot but still couldn't find proper solution.</p>
  <p>My Teams table,</p>
  <pre><code>ID | Team   | Branch | Year |
  ---|--------|----------|------|
  1  |Team A  | 9401     | 2020 |
  2  |Team B  | 9401     | 2020 |
  3  |Team C  | 9449     | 2020 |
  4  |Team D  | 9491     | 2019 |
  </code></pre>
  <p>My Team_Members table,</p>
  <pre><code>ID  | TeamID  | UserID | UserName |
  ----|---------|--------|----------|
  55  | 1       | 0001   | user1    |
  56  | 1       | 0002   | user2    |
  57  | 2       | 0003   | user3    |
  58  | 2       | 0004   | user4    |
  59  | 2       | 0005   | user5    |
  60  | 3       | 0006   | user6    |
  61  | 4       | 0007   | user7    |
  </code></pre>
  <p>Teams table has reference with column &quot;TeamID&quot; in Team_Members table. I can claim all relational fields with this query,</p>
  <pre><code>var query = _dbContext.Teams
      .Include(i =&gt; i.Team_Members)
      .Where(x=&gt; x.Year == &quot;2020&quot;)
      .ToList();
  </code></pre>
  <p>But I need to convert this query to following Object Pattern.</p>
  <p>Example:
  Year is required parameter, If I enter &quot;2020&quot; for year,
  I need to claim fields with following object pattern,</p>
  <pre><code>[
    {
      &quot;Branch&quot;:&quot;9401&quot;,
      &quot;Year&quot;:&quot;2020&quot;,
      &quot;Teams&quot;:[
        {
          &quot;TeamName&quot;:&quot;Team A&quot;,
          &quot;TeamMembers&quot;:[
            {
              &quot;UserName&quot;:&quot;user1&quot;,
              &quot;UserID&quot;:&quot;0001&quot;
            },
            {
              &quot;UserName&quot;:&quot;user2&quot;,
              &quot;UserID&quot;:&quot;0002&quot;
            }
          ]
        },
        {
          &quot;TeamName&quot;:&quot;Team B&quot;,
          &quot;TeamMembers&quot;:[
            {
              &quot;UserName&quot;:&quot;user3&quot;,
              &quot;UserID&quot;:&quot;0003&quot;
            },
            {
              &quot;UserName&quot;:&quot;user4&quot;,
              &quot;UserID&quot;:&quot;0004&quot;
            },
            {
              &quot;UserName&quot;:&quot;user5&quot;,
              &quot;UserID&quot;:&quot;0005&quot;
            }
          ]
        }
      ]
    },
    {
      &quot;Branch&quot;:&quot;9449&quot;,
      &quot;Year&quot;:&quot;2020&quot;,
      &quot;Teams&quot;:[
        {
          &quot;TeamName&quot;:&quot;Team C&quot;,
          &quot;TeamMembers&quot;:[
            {
              &quot;UserName&quot;:&quot;user6&quot;,
              &quot;UserID&quot;:&quot;0006&quot;
            }
          ]
        }
      ]
    }
  ]
  </code></pre>
  <p>Best Regards.</p>