2013-03-05 80 views
0

我正在使用Linq to SQL来访问我的SQL Ce数据库。Linq to SQL的Stackoverflow异常

var Logcontext = new LogContext(GCUtility.LconnectionPool.Connection); 
{   
var _ApplicationsK = (from u in Logcontext.Applications select u.PK_Key).ToList<int>(); 
} 

在上面的代码中PK_Key是数据库中自动递增的整数变量。它引发一个异常“在System.Data.SqlServerCe.dll中出现'System.StackOverflowException'类型的未处理的异常”。我尝试在Visual Studio上清理,重建,重新启动等。我正在使用Linq运行时版本v4.0.30319。我的代码有什么问题?

表结构如下所示。

PK_Key (Type = int, PrimaryKey = true, Identity = True, Identity increment = 1, seed =1) 

Username (Type = varchar, AllowNulls = True) 

的LINQ SqlMetal.exe产生下面的代码为coloumn PK_Key

[global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_PK_Key", AutoSync = AutoSync.OnInsert, DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)] 
    public int PK_Key 
    { 
     get 
     { 
      return this._PK_Key; 
     } 
     set 
     { 
      if ((this._PK_Key != value)) 
      { 
       this.OnPK_KeyChanging(value); 
       this.SendPropertyChanging(); 
       this._PK_Key = value; 
       this.SendPropertyChanged("PK_Key"); 
       this.OnPK_KeyChanged(); 
      } 
     } 
    } 
+0

表格有多少行?另外,你可以发布包含查询的方法的其余部分吗? '_ApplicationsK'应该分配在堆上,所以不管它的大小如何,它都不会导致SOException。更可能是因为意外将一个非常大的结构放在堆栈上。 – evanmcdonnal 2013-03-05 20:42:13

+2

当您遇到堆栈溢出异常时,寻找问题的好地方是堆栈跟踪。 – 2013-03-05 20:44:11

+0

插入工作没有任何问题。到目前为止,我只测试了30行以下。 – justcoding124 2013-03-05 20:44:22

回答

2

我想通了实际的问题,我有它继承了这个类的另一个子类。上面的代码在父类的构造函数中。我在我的父类中实例化了继承的子类,导致无限循环。愚蠢的我。