title: Entity Framework throwing Stack Overflow exceptions
body: <p>Entity Framework keeps throwing this exception.</p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.StackOverflowException' occured
    in mscorlib.dll</p>
  </blockquote>
  
  <p>The exception appears in the generated context class code when I call a stored procedure.</p>
  
  <p>There is no specific procedure it happens with and even simple procedures fail.</p>
  
  <p>I have tried deleting the EF model and recreating with no luck.</p>
  
  <p>This has worked fine in the past, no idea why it has suddenly started!</p>
  
  <p>All help appreciated.</p>
  
  <p>example EF generated code with the problem:</p>
  
  <pre><code>    public virtual ObjectResult&lt;GetVariant_Result&gt; GetVariant(Nullable&lt;int&gt; variantId)
      {
          var variantIdParameter = variantId.HasValue ?
              new ObjectParameter("VariantId", variantId) :
              new ObjectParameter("VariantId", typeof(int));
  
          return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction&lt;GetVariant_Result&gt;("GetVariant", variantIdParameter);
      }
  </code></pre>
  
  <p>The matching result class:</p>
  
  <pre><code>public partial class GetVariant_Result
  {
      public int VariantId { get; set; }
      public string Description { get; set; }
      public int ModelId { get; set; }
      public string ModelName { get; set; }
      public int BuildId { get; set; }
      public string ModelCode { get; set; }
      public string ProductionStart { get; set; }
      public string ProductionEnd { get; set; }
      public int EngineId { get; set; }
      public int FuelTypeId { get; set; }
      public string FuelTypeDescription { get; set; }
      public int TransmissionId { get; set; }
      public string TransmissionDescription { get; set; }
  }
  </code></pre>
  
  <p>The procedure that matches this code:</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[GetVariant]
      @VariantId int
  AS
  BEGIN
      SET NOCOUNT ON;
  
      SELECT      Variant.VariantId           VariantId,
                  Variant.[Description]       [Description],
                  Model.ModelId               ModelId,
                  Model.Name                  ModelName,
                  Build.BuildId               BuildId,
                  Build.ModelCode             ModelCode,
                  Build.ProductionStart       ProductionStart,
                  Build.ProductionEnd         ProductionEnd,
                  Engine.EngineId             EngineId,
                  FuelType.FuelTypeId         FuelTypeId,
                  FuelType.[Description]      FuelTypeDescription,
                  Transmission.TransmissionId TransmissionId,
                  Transmission.[Description]  TransmissionDescription
      FROM        Variant
      INNER JOIN  Build
      ON          Build.BuildId = Variant.BuildId
      INNER JOIN  Model
      ON          Model.ModelId = Build.ModelId
      INNER JOIN  Engine
      ON          Engine.EngineId = Variant.EngineId
      INNER JOIN  FuelType
      ON          FuelType.FuelTypeId = Engine.FuelTypeId
      INNER JOIN  Transmission
      ON          Transmission.TransmissionId = Variant.TransmissionId
      WHERE       Variant.VariantId = @VariantId
  
  END
  </code></pre>