title: .NET Core and EF relations : problem with getting data
body: <p><strong>The problem</strong></p>
  <p>I have two tables with a relation; I can get any data I want from one table or the other without any problem but I can't manage getting data from both together.</p>
  <p>The environment:</p>
  <ul>
  <li>Visual Studio 2022</li>
  <li>Webassembly Blazor project running on .NET 6.0</li>
  <li>Nuget packages
  <ul>
  <li>Microsoft.EntityFrameworkCore 6.0.1</li>
  <li>Pomelo.EntityFrameworkCore.MySql</li>
  </ul>
  </li>
  <li>Database MariaDb 13.3.31</li>
  </ul>
  <p>The way I've constructed the data environment:</p>
  <p>With PhpMyAdmin, I created the 2 tables with the relation.</p>
  <p>I then launched the scaffolding command in package manager console:</p>
  <pre><code>Scaffold-DbContext &quot;Server=192.168.0.22;user=MyUser;Password=MyPassword;Database=MyDb;&quot; 
           Pomelo.EntityFrameworkCore.MySql 
           -OutputDir Models -Context &quot;MySqlstockDataContext&quot; -DataAnnotations
  </code></pre>
  <p>After that, I created the controller with the VS2022 command &quot;Add new Controller&quot; and selected the &quot;API controller with actions using Entity Framework&quot;</p>
  <p>My models, <code>DbContext</code> and controllers were built by the tools of VS 2022, I didn't write any code for this.</p>
  <p>The database (a simple one with articles which can have movements (Input or Output of stock):</p>
  <p><img src="https://i.stack.imgur.com/O4qKl.png" alt="Screenshot of the database scheme" /></p>
  <p>This is the generated code for the model class &quot;Articles&quot;:</p>
  <p><a href="https://i.stack.imgur.com/vnkGL.png" rel="nofollow noreferrer">Screenshot of model class Articles</a></p>
  <p>This is the generated code for the model class &quot;Mouvements&quot;:</p>
  <p><a href="https://i.stack.imgur.com/n8EQa.png" rel="nofollow noreferrer">Screenshot of model class Mouvements</a></p>
  <p>This is the generated code for the model class &quot;DbContext&quot;:</p>
  <p><a href="https://i.stack.imgur.com/GVDfa.png" rel="nofollow noreferrer">Screenshot of DbContext</a></p>
  <p>ArticlesController:</p>
  <p><a href="https://i.stack.imgur.com/8Qy5Y.png" rel="nofollow noreferrer">Screenshot of ArticlesController</a></p>
  <p>MouvementsController:</p>
  <p><a href="https://i.stack.imgur.com/GmC3t.png" rel="nofollow noreferrer">Screenshot of MouvementsController</a></p>
  <p>The Razor page:</p>
  <p><a href="https://i.stack.imgur.com/ppJpc.png" rel="nofollow noreferrer">Screenshot for Razor page displaying the data in browser</a></p>
  <p>What I have tried already:</p>
  <p>In this razor page, the line</p>
  <pre><code>&lt;td&gt;@mouvement.IdArticleNavigation.NomArticle&lt;/td&gt;
  </code></pre>
  <p>is the problem even if in the <code>MouvementsController</code>, I use</p>
  <pre><code>return await _context.Mouvements
                       .Include(e =&gt;  e.IdArticleNavigation.NomArticle)
                       .ToListAsync();
  </code></pre>
  <p>instead of just</p>
  <pre><code>return await _context.Mouvements.ToListAsync();
  </code></pre>
  <p>To make the things go the right way, I think I should write:</p>
  <pre><code>&lt;td&gt;@Mouvement. Articles.NomArticle&lt;/td&gt;
  </code></pre>
  <p>in the Razor page and</p>
  <pre><code>return await _context.Mouvements
                       .Include(e =&gt; e.Articles.NomArticle)
                       .ToListAsync();
  </code></pre>
  <p>in the MouvementsController.</p>
  <p>But the intellisense doesn't give me this possibility. The only thing that intellisense gives me for linking the articles and the mouvements is <code>Include.IdArticleNavigation.NomArticle</code> but this doesn't work.</p>
  <p>This is the error I see in the browser console:</p>
  <blockquote>
  <p>An unhandled error occurred</p>
  </blockquote>
  <p>In the VS 2022 console, the error says</p>
  <blockquote>
  <p>&quot;e.IdArticleNavigation.NomArticle&quot; is invalid inside an include.</p>
  </blockquote>
  <p><a href="https://i.stack.imgur.com/FdEQs.png" rel="nofollow noreferrer">Screenshot of the error</a></p>
  <p>I must admit I'm new to .NET Core, C#, Visual Studio and I just code for hobby. So, all the examples I saw in the Web was not very clear for me (complex developers vocabulary !)</p>
  <p>Hope someone will be able to help me a simple way, if possible !</p>
  <hr />
  <p>Hello Caius,
  thanks a lot for this fast and sharp response which I think a understand quite good. However, maybe I don't use your advices as it should be because I can't still manage to query the two tables.
  Under, you can see a picture of what I have in the Intellisense propositions when I try to reproduce the code you suggest.<br/>
  <a href="https://i.stack.imgur.com/osOBh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/osOBh.png" alt="Picture with Intellisense propositions" /></a>
  We can see than there are no propositions of properties coming from the &quot;article&quot; table.</p>
  <p>To be sure my question were clear, let me tell what result I try to have : I'd like to get all the properties of the &quot;mouvement&quot; table and the &quot;nom_article&quot; property (and others also) corresponding in the &quot;article&quot; table. In SQL I think it would correspond to : <strong>SELECT * FROM mouvement INNER JOIN article ON mouvement.id_article = article.id_article;</strong> that would allow to finally get the properties to display a table like this :</p>
  <p>id_mvt|id article|type_mvt|Qte_mvt|date_mvt|<strong>nom_article</strong></p>
  <p><a href="https://i.stack.imgur.com/azWMt.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/azWMt.jpg" alt="ERROR IN CONSOLE" /></a>
  Best regards.</p>