实体框架抛出Stack Overflow异常

时间:2016-05-18 12:56:54

标签: c# visual-studio-2013 sql-server-2012 entity-framework-6

实体框架不断抛出此异常。

  

未处理的类型' System.StackOverflowException'发生   在mscorlib.dll中

当我调用存储过程时,生成的上下文类代码中会出现异常。

没有特定的程序,即使是简单的程序也会失败。

我尝试删除EF模型并重新创建,但没有运气。

这在过去运作良好,不知道它为什么突然开始了!

所有帮助表示赞赏。

示例EF生成的代码有问题:

    public virtual ObjectResult<GetVariant_Result> GetVariant(Nullable<int> variantId)
    {
        var variantIdParameter = variantId.HasValue ?
            new ObjectParameter("VariantId", variantId) :
            new ObjectParameter("VariantId", typeof(int));

        return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<GetVariant_Result>("GetVariant", variantIdParameter);
    }

匹配结果类:

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; }
}

与此代码匹配的过程:

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

0 个答案:

没有答案