【问题标题】:An unhandled exception of type 'System.StackOverflowException' Entity Framework“System.StackOverflowException”实体框架类型的未处理异常
【发布时间】:2018-01-04 14:32:34
【问题描述】:

我遇到了最奇怪的问题;我降级到 ef5 6 仍在为我玩,但现在我得到关注它在下面的行崩溃

 /// <summary>
 /// Initializes a new SMBASchedulerEntities object using the connection string found in the 'SMBASchedulerEntities' section of the application configuration file.
 /// </summary>
public SMBASchedulerEntities() : base("name=SMBASchedulerEntities", "SMBASchedulerEntities")
{
    this.ContextOptions.LazyLoadingEnabled = true;
    OnContextCreated();
}

有问题的错误是

在 mscorlib.dll 中发生了“System.StackOverflowException”类型的未处理异常

我有一个属性可以让我在其他表单上调用我的保存上下文

private SMBASchedulerEntities _SourceEntities;

public SMBASchedulerEntities SourceEntities
{
    get
    {
         _SourceEntities = new SMBASchedulerEntities();
         return SourceEntities;
    }
}

我不知道这里发生了什么,因为我以前从未遇到过这个错误。

【问题讨论】:

    标签: c# entity-framework


    【解决方案1】:

    您在属性 getter 中引用您的属性

     private SMBASchedulerEntities _SourceEntities;
     public SMBASchedulerEntities SourceEntities
     {
          get
          {
    
              _SourceEntities = new SMBASchedulerEntities();
    
    
              return SourceEntities; <-- should be _SourceEntities 
          }
    }
    

    基本上,如果调用中的调用过多,则会引发此异常。 (或在本例中为“无限”)

    【讨论】:

      猜你喜欢
      • 2011-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多