title: What is the most correct method of updating an Aggregate through an Aggregate Root?
body: <p>Following the good practices of DDD, Aggregate and Aggregate Root. I have the following scenario:</p>
  
  <ul>
  <li><code>User</code> (Aggregate Root)</li>
  <li>A collection of <code>UserEmail</code> (inside <code>User</code>)</li>
  </ul>
  
  <p>Imagining that I have registered a User with 10 Emails, what would be the most correct and perfomable way of updating one of these emails?</p>
  
  <p><strong>Method 1</strong></p>
  
  <pre><code>static void UpdateEmailForExistingUserMethod1()
  {
      var userId = new Guid("f0cd6e3e-b95b-4dab-bb0b-7e6c6e1b0855");
      var emailId = new Guid("804aff75-8e48-4f53-b55d-8d3ca76a2df9");
  
      using(var repository = new UserRepository())
      {
          // I'm going to return the user with all their emails?
          // I will not have performance problems for bringing all emails from this user?
          var user = repository.GetUserById(userId);
  
          if (user == null)
          {
              Console.WriteLine("User not found");
              return;
          }
  
          // Updating Email in Aggregate Root
          user.UpdateEmail(emailId, "updated1@email.com");
  
          // Commit in repository
          if (repository.Commit() &gt; 0)
          {
              Console.WriteLine("E-mail updated with method 1!");
          };
      }
  }
  </code></pre>
  
  <p><strong>Method 2:</strong></p>
  
  <pre><code>static void UpdateEmailForExistingUserMethod2()
  {
      var usuarioId = new Guid("f0cd6e3e-b95b-4dab-bb0b-7e6c6e1b0855");
      var emailId = new Guid("3b9c2f36-659e-41e8-a1c6-d879ab58352c");
  
      using(var usuarioRepository = new UserRepository())
      {
          if (!usuarioRepository.UserExists(usuarioId))
          {
              Console.WriteLine("User not found");
              return;
          }
  
          if (!usuarioRepository.EmailExists(emailId))
          {
              Console.WriteLine("E-mail not found");
              return;
          }
  
          // Grab only the email that I will update from the repository, 
          // optimizing performance
          var usuarioEmail = usuarioRepository.GetEmailById(emailId);
  
          // Updates the e-mail through a method of the e-mail entity itself
          usuarioEmail.Update("updated2@email.com");
  
          // Commit in repository
          if (usuarioRepository.Commit() &gt; 0)
          {
              Console.WriteLine("E-mail updated with method 2!");
          };
      }
  }
  </code></pre>