Reputation: 2200
I am using Linq to SQL to access my SQL Ce database.
var Logcontext = new LogContext(GCUtility.LconnectionPool.Connection);
{
var _ApplicationsK = (from u in Logcontext.Applications select u.PK_Key).ToList<int>();
}
In the above code PK_Key is an auto-incremented integer variable in database. It throws an exception "An unhandled exception of type 'System.StackOverflowException' occurred in System.Data.SqlServerCe.dll". I tried cleaning, rebuilding, restarting etc on Visual Studio. I am using Linq runtime version v4.0.30319. Whats wrong in my code?
The table structure is like below.
PK_Key (Type = int, PrimaryKey = true, Identity = True, Identity increment = 1, seed =1 )
Username (Type = varchar, AllowNulls = True)
Linq SqlMetal.exe generated the following code for the 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();
}
}
}
Upvotes: 0
Views: 902
Reputation: 2200
I figured out the actual problem, I had another child class which inherited this class. The above code was in the constructor of parent class. I instantiated inherited child class within my parent class causing an infinite loop. Stupid me.
Upvotes: 2