title: Should repositories be atomic?
body: <p>I am designing my repositories and I have a doubt. For example when creating a new User, I have to add entries on different tables. Right now I use something like:</p>
  
  <pre><code>public User CreateNewUser()
  {
      try
      {
          using (var con = new SqlConnection(_SecureConnectionString))
          {
              con.Open();
  
              using (var transaction = con.BeginTransaction())
              {
                 User user = //User Repository query to INSERT the user on dbo.Users and return object
  
                 user.Items = // Item Repository query to INSERT on dbo.Items that have a FK to dbo.Users
                 user.Whatever = // Whatever repository call to INSERT on tables that are related to the new user
  
                 transaction.Commit();
              }
          }
      catch (Exception ex)
      {
          transaction.Rollback();
          throw;
      }
  }
  </code></pre>
  
  <p>My question is, if creating a new user and it always have to create entries on different tables managed by other repositories, should I avoid being so atomic and do it on a single query on the UserRepository even if it insert on other tables? I am doing 3 database hits when I could do it on a single one.</p>