Querying a very large table using Entity to SQL, works fine in all other parts of code and even works the first time. However, on the second time of performing an identical request, it will give a stack overflow exception. When breaking up the linq query - it happens on the .FirstOrDefault()
I believe that is when linq triggers the query to happen, such as how .ToList() kicks off the query.
I'm just confused on why a stack overflow exception would happen on a non-recursion call, as there are only 3 methods in the call stack. Since it happens on the second call every time, maybe it is building onto an existing stack outside of the scope, or maybe there is something in memory from the previous call to the DB. Anyone have any tips? let me know if I can add additional info... thank you
Small code example:
int myId = context.TABLE_NAME.Where(x => x.ID == myId).FirstOrDefault().ID;
where TABLE_NAME is a very large table, 300+ million records, and inside of the table class it does have an unusual constructor that I have not seen in most entity classes.
public partial class TABLE_NAME
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public TABLE_NAME()
{
this.OTHER_TABLE_NAME = new HashSet<OTHER_TABLE_NAME >();
}
public int ID { get; set; }
...
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<OTHER_TABLE_NAME> OTHER_TABLE_NAME{ get; set; }
}