While accessing a list of entity, the system throws an “Out of Memory” exception.
The call stack has a block of calls which repeats till the application hits out of memory.
Call stack:
.
.
.
at System.Data.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n)
/* Repeating Block */
at System.Data.Query.InternalTrees.BasicOpVisitorOfNode.VisitChildren(Node n)
at System.Data.Query.PlanCompiler.JoinElimination.VisitDefaultForAllNodes(Node n)
at System.Data.Query.PlanCompiler.JoinElimination.VisitDefault(Node n)
at System.Data.Query.InternalTrees.BasicOpVisitorOfNode.VisitPhysicalOpDefault(PhysicalOp op, Node n)
at System.Data.Query.InternalTrees.BasicOpVisitorOfT`1.Visit(PhysicalProjectOp op, Node n)
at System.Data.Query.InternalTrees.PhysicalProjectOp.Accept[TResultType](BasicOpVisitorOfT`1 v, Node n)
at System.Data.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n)
/* Repeating Block */
at System.Data.Query.PlanCompiler.JoinElimination.Process()
at System.Data.Query.PlanCompiler.PlanCompiler.Compile(List`1& providerCommands, ColumnMap& resultColumnMap, Int32& columnCount, Set`1& entitySets)
at System.Data.Query.PlanCompiler.PlanCompiler.Compile(DbCommandTree ctree, List`1& providerCommands, ColumnMap& resultColumnMap, Int32& columnCount, Set`1& entitySets)
at System.Data.EntityClient.EntityCommandDefinition..ctor(DbProviderFactory storeProviderFactory, DbCommandTree commandTree)
at System.Data.EntityClient.EntityProviderServices.CreateCommandDefinition(DbProviderFactory storeProviderFactory, DbCommandTree commandTree)
at System.Data.EntityClient.EntityProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
at System.Data.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree)
at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Prepare(ObjectContext context, DbQueryCommandTree tree, Type elementType, MergeOption mergeOption, Span span, ReadOnlyCollection`1 compiledQueryParameters, AliasGenerator aliasGenerator)
at System.Data.Objects.EntitySqlQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
at System.Data.Objects.ObjectQuery`1.Execute(MergeOption mergeOption)
at System.Data.Objects.DataClasses.EntityCollection`1.Load(List`1 collection, MergeOption mergeOption)
at System.Data.Objects.DataClasses.EntityCollection`1.Load(MergeOption mergeOption)
at System.Data.Objects.DataClasses.RelatedEnd.Load()
at System.Data.Objects.DataClasses.RelatedEnd.DeferredLoad()
at System.Data.Objects.Internal.LazyLoadBehavior.LoadProperty[TItem](TItem propertyValue, String relationshipName, String targetRoleName, Boolean mustBeNull, Object wrapperObject)
at System.Data.Objects.Internal.LazyLoadBehavior.<>c__DisplayClass7`2.<GetInterceptorDelegate>b__1(TProxy proxy, TItem item)
Any clue on what might be the issue here or probably some hints on how to go about debugging the issue?
The hierarchy that I’m trying to model is a little big, with 3 levels of inheritance:

There are around 20 classes which are derived from A1, and about 30 classes which derive from A2. The system goes ‘Out of Memory’ when I try to access an object of type ‘A’. The issue seems to be with how the EF tries to generate execution plans and corresponding SQL to access an item of type ‘A’.
I was able to fix the issue with moving the mapping from TPT to TPH. I also had to avoid a documented bug in EF Code First by renaming columns with same name.
Now I’m stuck on an issue with EF start up time which is spanning hours. I have posted the same at SO, here.