title: Business logic in constructor - C# / Linq to Sql
body: <p>I'm extending (not sure if it's the right word here) a partial Cart class that was generated in the Linq to SQL database model.</p>
  
  <p>The business logic is that there can be only one Cart per customer. If a customer doesn't have a cart, it should be created; if a customer has a cart, it should be returned.</p>
  
  <p>Here's what I'm doing: </p>
  
  <pre><code>public partial class Cart
  {
      //the rest of the Cart class is in the .dbml file created by L2S
      public Cart(int userId)
      {
          Cart c = GetCurrentCart(userId);
          this.CartId = c.CartId ;
          this.UserId = c.UserId;
      }
  
      public Cart GetCurrentCart(int userId)
      {
          Cart currentCart = new Cart();
  
          // if cart exists - get it from DB
          //if not - create it, save in DB, and get if right out
          //all of this is done with Linq to SQL
  
          return currentCart;
      }
  }
  </code></pre>
  
  <p>Calling a method from the constructor just doesn't seem right.  Am I enforcing the business logic the right way?</p>