title: How to write this C# statement in linq
body: <p>I'm trying to get related tables Adress and PlzOrt into an object User. 
  The relationships are as follows:
  <p><strong>User 1:1 Adress</strong>
  <p><strong>Adress n:1 PlzOrt</strong></p>
  
  <p><strong>Entities Scaffolded from the DB</strong></p>
  
  <pre><code>public partial class User
  {
      //No hash sets for Adress Scaffolded (probably unnecessary since the is 
      //only ever one address per user
  
      public int IdUser { get; set; }
      public int? FidAdresse { get; set; }
      public string Email { get; set; }
      public string Vorname { get; set; }
      public string Nachmname { get; set; }
  
      [ForeignKey("FidAdresse")]
      [InverseProperty("User")]
      public virtual Adresse FidAdresseNavigation { get; set; }
  }
  
  public partial class Adresse
  {
      public Adresse()
      {
          User = new HashSet&lt;User&gt;();
      }
  
      public int IdAdresse { get; set; }
      public int FidPlzOrt { get; set; }
      public string Strasse { get; set; }
      public string Hausnr { get; set; }
  
      [ForeignKey("FidPlzOrt")]
      [InverseProperty("Adresse")]
      public virtual PlzOrt FidPlzOrtNavigation { get; set; }
      [InverseProperty("FidAdresseNavigation")]
      public virtual ICollection&lt;User&gt; User { get; set; }
  }
  
  public partial class PlzOrt
  {
      public PlzOrt()
      {
          Adresse = new HashSet&lt;Adresse&gt;();
      }
  
      public int IdPlzOrt { get; set; }
      public string Plz { get; set; }
      public string Ort { get; set; }
  
      [InverseProperty("FidPlzOrtNavigation")]
      public virtual ICollection&lt;Adresse&gt; Adresse { get; set; }
  }
  </code></pre>
  
  <p>Here´s the linq that does not work. </p>
  
  <pre><code>return _context.User
              .Include(u =&gt; u.FidPermissionNavigation)
              .Include(c =&gt; c.FidAdresseNavigation)
                  .ThenInclude(c =&gt; c.FidPlzOrtNavigation)
              .FirstOrDefault(c =&gt; c.IdUser == id);
  </code></pre>
  
  <p>The linq work when I don´t include the "ThenInclude(c => c.FidPlzOrtNavigation)" statement, but I want this information in my object. </p>
  
  <p>Here´s the C# that gives me the expected results:</p>
  
  <pre><code> public User GetUser(int id)
      {
  
          foreach (User user in _context.User)
          {
              if (user.IdUser == id)
              {
                  foreach (Adresse adresse in _context.Adresse)
                  {
                      if (adresse.IdAdresse == user.FidAdresse)
                      {
                          user.FidAdresseNavigation = adresse;
  
                          foreach (PlzOrt plzOrt in _context.PlzOrt)
                          {
                              if (plzOrt.IdPlzOrt == adresse.FidPlzOrt)
                              {
                                  user.FidAdresseNavigation.FidPlzOrtNavigation = plzOrt;
                                  break;
                              }
                          }
  
                          break;
                      }
                  }
  
                  return user;
              }
          }
  
          return null;
   }
  </code></pre>
  
  <p>Translating this linq statement would be of great help. Thanks in advance.</p>
  
  <p><strong>Generated db_context code in case you are interested or this helps</strong></p>
  
  <pre><code>modelBuilder.Entity&lt;User&gt;(entity =&gt;
          {
              entity.HasKey(e =&gt; e.IdUser)
                  .HasName("PRIMARY");
  
              entity.HasIndex(e =&gt; e.FidAdresse)
                  .HasName("fk_User_Adresse1_idx");
  
              entity.HasOne(d =&gt; d.FidAdresseNavigation)
                  .WithMany(p =&gt; p.User)
                  .HasForeignKey(d =&gt; d.FidAdresse)
                  .HasConstraintName("fk_User_Adresse1");
          });
  
  modelBuilder.Entity&lt;Adresse&gt;(entity =&gt;
          {
              entity.HasKey(e =&gt; e.IdAdresse)
                  .HasName("PRIMARY");
  
              entity.HasIndex(e =&gt; e.FidPlzOrt)
                  .HasName("fk_Adresse_plz_ort1_idx");
  
              entity.HasOne(d =&gt; d.FidPlzOrtNavigation)
                  .WithMany(p =&gt; p.Adresse)
                  .HasForeignKey(d =&gt; d.FidPlzOrt)
                  .OnDelete(DeleteBehavior.ClientSetNull)
                  .HasConstraintName("fk_Adresse_plz_ort1");
          });
  
  modelBuilder.Entity&lt;PlzOrt&gt;(entity =&gt;
          {
              entity.HasKey(e =&gt; e.IdPlzOrt)
                  .HasName("PRIMARY");
          });
  </code></pre>