title: Entity Framework - System.StackOverflowException
body: <p>I am new to entity framework and have hit an issue trying to insert new items into a lookup table.</p>
  
  <p>The error is - </p>
  
  <blockquote>
    <p>"An unhandled exception of type <code>System.StackOverflowException</code>
    occurred in mscorlib.dll"</p>
  </blockquote>
  
  <p>It is thrown in the final code block below where public <code>DIEMEntities()</code> is called.</p>
  
  <p>It occurs whenever I add a new item, I can update items ok.</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>The code is -</p>
  
  <pre><code>protected void OnSave(object sender, EventArgs e)
      {
          ArrayList validationErrors = new ArrayList();
          ContactTypeEO contactType = new ContactTypeEO();
  
          if (uxID.Value.Length &gt; 0)
          {
              //Updating
              contactType.Id = int.Parse(uxID.Value);
          }
  
          contactType.Name = uxName.Text;
          contactType.ExpressionValidator = uxExpression.Text;
  
          contactType.Save(ref validationErrors);
  
          if (validationErrors.Count &gt; 0)
          {
              ShowValidationMessages(validationErrors);
          }
          else
          {
              this.RefreshUI();
          }
      } 
  
  public bool Save(ref ArrayList validationErrors)
      {
          ValidateSave(ref validationErrors);
  
          if (validationErrors.Count == 0)
          {
              if (Id == 0)
              {
                  ContactTypeData.Insert(Name, ExpressionValidator);
              }
              else
              {
                  ContactTypeData.Update(Id, Name, ExpressionValidator);
              }
              return true;
          }
          else
          {
              return false;
          }
      } 
  
  /// &lt;summary&gt;
      /// Inserts the new Contact Type.
      /// &lt;/summary&gt;
      /// &lt;param name="name"&gt;The name.&lt;/param&gt;
      /// &lt;param name="validator"&gt;The validator.&lt;/param&gt;
      public static void Insert(string name, string validator)
      {
          using (DIEMEntities diemEntities = new DIEMEntities())
          {
              Insert(name, validator);
          }
      }
  
      /// &lt;summary&gt;
      /// Inserts the new Contact Type.
      /// &lt;/summary&gt;
      /// &lt;param name="diemEntities"&gt;The DIEM Entities.&lt;/param&gt;
      /// &lt;param name="name"&gt;The name.&lt;/param&gt;
      /// &lt;param name="validator"&gt;The validator.&lt;/param&gt;
      public static void Insert(DIEMEntities diemEntities, string name, string validator)
      {
          diemEntities.usp_ContactTypes_Insert(name, validator);
      } 
  
  public partial class DIEMEntities : DbContext
  {
      public DIEMEntities()
          : base("name=DIEMEntities")
      {
      }
  
  ... OTHER CODE}
  </code></pre>