问题
I'm facing an issue with EF taking a lot of time (spanning hours) to initialize models. The model is as given below. There are around 20 classes which are derived from A1, and about 30 classes which derive from A2.

I had to move from TPT to TPH strategy to fix an issue related to memory usage. And since then I'm trying to figure out this issue.
The issue is produced by just creating a single instance of type 'A', adding it to a List<A>
property of another entity and committing those changes. At this moment, it has already taken about 2.5 hours, and still hasn't committed the changes yet!
Breaking into the code (after waiting for about an hour to finish), the call stack is:
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.IfThenElse(System.Data.Common.Utils.Boolean.Vertex condition, System.Data.Common.Utils.Boolean.Vertex then, System.Data.Common.Utils.Boolean.Vertex else) + 0x14e bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.And.AnonymousMethod__1(System.Data.Common.Utils.Boolean.Vertex left, System.Data.Common.Utils.Boolean.Vertex right) + 0x29 bytes
System.Core.dll!System.Linq.Enumerable.Aggregate<System.Data.Common.Utils.Boolean.Vertex,System.Data.Common.Utils.Boolean.Vertex>(System.Collections.Generic.IEnumerable<System.Data.Common.Utils.Boolean.Vertex> source, System.Data.Common.Utils.Boolean.Vertex seed, System.Func<System.Data.Common.Utils.Boolean.Vertex,System.Data.Common.Utils.Boolean.Vertex,System.Data.Common.Utils.Boolean.Vertex> func) + 0x99 bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Solver.And(System.Collections.Generic.IEnumerable<System.Data.Common.Utils.Boolean.Vertex> children) + 0x90 bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.ToDecisionDiagramConverter<System.Data.Common.Utils.Boolean.DomainConstraint<System.Data.Mapping.ViewGeneration.Structures.BoolLiteral,System.Data.Mapping.ViewGeneration.Structures.Constant>>.VisitAnd(System.Data.Common.Utils.Boolean.AndExpr<System.Data.Common.Utils.Boolean.DomainConstraint<System.Data.Mapping.ViewGeneration.Structures.BoolLiteral,System.Data.Mapping.ViewGeneration.Structures.Constant>> expression) + 0x77 bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.AndExpr<System.__Canon>.Accept<System.__Canon>(System.Data.Common.Utils.Boolean.Visitor<System.__Canon,System.__Canon> visitor) + 0xc bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.ToDecisionDiagramConverter<System.Data.Common.Utils.Boolean.DomainConstraint<System.Data.Mapping.ViewGeneration.Structures.BoolLiteral,System.Data.Mapping.ViewGeneration.Structures.Constant>>.TranslateToRobdd(System.Data.Common.Utils.Boolean.BoolExpr<System.Data.Common.Utils.Boolean.DomainConstraint<System.Data.Mapping.ViewGeneration.Structures.BoolLiteral,System.Data.Mapping.ViewGeneration.Structures.Constant>> expr, System.Data.Common.Utils.Boolean.ConversionContext<System.Data.Common.Utils.Boolean.DomainConstraint<System.Data.Mapping.ViewGeneration.Structures.BoolLiteral,System.Data.Mapping.ViewGeneration.Structures.Constant>> context) + 0x72 bytes
System.Data.Entity.dll!System.Data.Common.Utils.Boolean.Converter<System.Data.Common.Utils.Boolean.DomainConstraint<System.Data.Mapping.ViewGeneration.Structures.BoolLiteral,System.Data.Mapping.ViewGeneration.Structures.Constant>>.Converter(System.Data.Common.Utils.Boolean.BoolExpr<System.Data.Common.Utils.Boolean.DomainConstraint<System.Data.Mapping.ViewGeneration.Structures.BoolLiteral,System.Data.Mapping.ViewGeneration.Structures.Constant>> expr, System.Data.Common.Utils.Boolean.ConversionContext<System.Data.Common.Utils.Boolean.DomainConstraint<System.Data.Mapping.ViewGeneration.Structures.BoolLiteral,System.Data.Mapping.ViewGeneration.Structures.Constant>> context) + 0x46 bytes
System.Data.Entity.dll!System.Data.Mapping.ViewGeneration.QueryRewriting.FragmentQueryProcessor.IsSatisfiable(System.Data.Mapping.ViewGeneration.Structures.BoolExpression condition) + 0xac bytes
System.Data.Entity.dll!System.Data.Mapping.ViewGeneration.QueryRewriting.FragmentQueryProcessor.IsSatisfiable(System.Data.Mapping.ViewGeneration.QueryRewriting.FragmentQuery query) + 0x8 bytes
System.Data.Entity.dll!System.Data.Mapping.ViewGeneration.Structures.CellTreeNode.IsEmptyRightFragmentQuery.get() + 0x1e bytes
System.Data.Entity.dll!System.Data.Mapping.ViewGeneration.BasicViewGenerator.IsDisjoint(System.Data.Mapping.ViewGeneration.Structures.CellTreeNode n1, System.Data.Mapping.ViewGeneration.Structures.CellTreeNode n2) + 0xbb bytes
System.Data.Entity.dll!System.Data.Mapping.ViewGeneration.BasicViewGenerator.TryAddChildToGroup(System.Data.Mapping.ViewGeneration.Structures.CellTreeOpType opTypeToIsolate, System.Data.Mapping.ViewGeneration.Structures.CellTreeNode childNode, System.Data.Mapping.ViewGeneration.Structures.OpCellTreeNode groupNode) + 0x3f bytes
System.Data.Entity.dll!System.Data.Mapping.ViewGeneration.BasicViewGenerator.IsolateByOperator(System.Data.Mapping.ViewGeneration.Structures.CellTreeNode rootNode, System.Data.Mapping.ViewGeneration.Structures.CellTreeOpType opTypeToIsolate) + 0x1eb bytes
System.Data.Entity.dll!System.Data.Mapping.ViewGeneration.BasicViewGenerator.CreateViewExpression() + 0xeb bytes
System.Data.Entity.dll!System.Data.Mapping.ViewGeneration.QueryRewriting.QueryRewriter.GenerateViewComponents() + 0x12a bytes
System.Data.Entity.dll!System.Data.Mapping.ViewGeneration.ViewGenerator.GenerateViewsForExtentAndType(System.Data.Metadata.Edm.EdmType generatedType, System.Data.Mapping.ViewGeneration.ViewgenContext context, System.Data.Mapping.ViewGeneration.Structures.CqlIdentifiers identifiers, System.Data.Common.Utils.KeyToListMap<System.Data.Metadata.Edm.EntitySetBase,System.Data.Mapping.ViewGeneration.GeneratedView> views, System.Data.Mapping.ViewGeneration.ViewGenMode mode) + 0x2f bytes
System.Data.Entity.dll!System.Data.Mapping.ViewGeneration.ViewGenerator.GenerateDirectionalViewsForExtent(System.Data.Mapping.ViewGeneration.Structures.ViewTarget viewTarget, System.Data.Metadata.Edm.EntitySetBase extent, System.Data.Mapping.ViewGeneration.Structures.CqlIdentifiers identifiers, System.Data.Common.Utils.KeyToListMap<System.Data.Metadata.Edm.EntitySetBase,System.Data.Mapping.ViewGeneration.GeneratedView> views) + 0x58 bytes
System.Data.Entity.dll!System.Data.Mapping.ViewGeneration.ViewGenerator.GenerateDirectionalViews(System.Data.Mapping.ViewGeneration.Structures.ViewTarget viewTarget, System.Data.Mapping.ViewGeneration.Structures.CqlIdentifiers identifiers, System.Data.Common.Utils.KeyToListMap<System.Data.Metadata.Edm.EntitySetBase,System.Data.Mapping.ViewGeneration.GeneratedView> views) + 0xce bytes
System.Data.Entity.dll!System.Data.Mapping.ViewGeneration.ViewGenerator.GenerateAllBidirectionalViews(System.Data.Common.Utils.KeyToListMap<System.Data.Metadata.Edm.EntitySetBase,System.Data.Mapping.ViewGeneration.GeneratedView> views, System.Data.Mapping.ViewGeneration.Structures.CqlIdentifiers identifiers) + 0xd7 bytes
System.Data.Entity.dll!System.Data.Mapping.ViewGeneration.ViewgenGatekeeper.GenerateViewsFromCells(System.Collections.Generic.List<System.Data.Mapping.ViewGeneration.Structures.Cell> cells, System.Data.Mapping.ViewGeneration.ConfigViewGenerator config, System.Data.Mapping.ViewGeneration.Structures.CqlIdentifiers identifiers, System.Data.Mapping.StorageEntityContainerMapping containerMapping) + 0x1aa bytes
System.Data.Entity.dll!System.Data.Mapping.ViewGeneration.ViewgenGatekeeper.GenerateViewsFromMapping(System.Data.Mapping.StorageEntityContainerMapping containerMapping, System.Data.Mapping.ViewGeneration.ConfigViewGenerator config) + 0xbf bytes
System.Data.Entity.dll!System.Data.Mapping.StorageMappingItemCollection.ViewDictionary.SerializedGenerateViews(System.Data.Mapping.StorageEntityContainerMapping entityContainerMap, System.Collections.Generic.Dictionary<System.Data.Metadata.Edm.EntitySetBase,System.Data.Mapping.ViewGeneration.GeneratedView> resultDictionary) + 0x3a bytes
System.Data.Entity.dll!System.Data.Mapping.StorageMappingItemCollection.ViewDictionary.SerializedGetGeneratedViews(System.Data.Metadata.Edm.EntityContainer container) + 0xd2 bytes
System.Data.Entity.dll!System.Data.Common.Utils.Memoizer<System.__Canon,System.__Canon>.Evaluate.AnonymousMethod__0() + 0x13 bytes
System.Data.Entity.dll!System.Data.Common.Utils.Memoizer<System.Data.Metadata.Edm.EntityContainer,System.Collections.Generic.Dictionary<System.Data.Metadata.Edm.EntitySetBase,System.Data.Mapping.ViewGeneration.GeneratedView>>.Result.GetValue() + 0x69 bytes
System.Data.Entity.dll!System.Data.Common.Utils.Memoizer<System.Data.Metadata.Edm.EntityContainer,System.Collections.Generic.Dictionary<System.Data.Metadata.Edm.EntitySetBase,System.Data.Mapping.ViewGeneration.GeneratedView>>.Evaluate(System.Data.Metadata.Edm.EntityContainer arg) + 0x6e bytes
System.Data.Entity.dll!System.Data.Mapping.StorageMappingItemCollection.ViewDictionary.GetGeneratedView(System.Data.Metadata.Edm.EntitySetBase extent, System.Data.Metadata.Edm.MetadataWorkspace workspace, System.Data.Mapping.StorageMappingItemCollection storageMappingItemCollection) + 0x49 bytes
System.Data.Entity.dll!System.Data.Mapping.Update.Internal.ViewLoader.InitializeEntitySet(System.Data.Metadata.Edm.EntitySetBase entitySetBase, System.Data.Metadata.Edm.MetadataWorkspace workspace) + 0x74 bytes
System.Data.Entity.dll!System.Data.Mapping.Update.Internal.ViewLoader.SyncInitializeEntitySet<System.__Canon,System.__Canon>(System.Data.Metadata.Edm.EntitySetBase entitySetBase, System.Data.Metadata.Edm.MetadataWorkspace workspace, System.Func<System.__Canon,System.__Canon> evaluate, System.__Canon arg) + 0xdf bytes
System.Data.Entity.dll!System.Data.Mapping.Update.Internal.ViewLoader.SyncGetValue<System.Data.Metadata.Edm.AssociationSet,System.Data.Mapping.Update.Internal.AssociationSetMetadata>(System.Data.Metadata.Edm.EntitySetBase entitySetBase, System.Data.Metadata.Edm.MetadataWorkspace workspace, System.Collections.Generic.Dictionary<System.Data.Metadata.Edm.AssociationSet,System.Data.Mapping.Update.Internal.AssociationSetMetadata> dictionary, System.Data.Metadata.Edm.AssociationSet key) + 0x9c bytes
System.Data.Entity.dll!System.Data.Mapping.Update.Internal.UpdateTranslator.ValidateAndRegisterStateEntry(System.Data.IEntityStateEntry stateEntry) + 0x109 bytes
System.Data.Entity.dll!System.Data.Mapping.Update.Internal.UpdateTranslator.LoadStateEntry(System.Data.IEntityStateEntry stateEntry) + 0x23 bytes
System.Data.Entity.dll!System.Data.Mapping.Update.Internal.UpdateTranslator.PullModifiedEntriesFromStateManager() + 0x156 bytes
System.Data.Entity.dll!System.Data.Mapping.Update.Internal.UpdateTranslator.ProduceCommands() + 0x1a bytes
System.Data.Entity.dll!System.Data.Mapping.Update.Internal.UpdateTranslator.Update(System.Data.IEntityStateManager stateManager, System.Data.IEntityAdapter adapter) + 0xc9 bytes
System.Data.Entity.dll!System.Data.EntityClient.EntityAdapter.Update(System.Data.IEntityStateManager entityCache) + 0x93 bytes
System.Data.Entity.dll!System.Data.Objects.ObjectContext.SaveChanges(System.Data.Objects.SaveOptions options) + 0x23c bytes
EntityFramework.dll!System.Data.Entity.Internal.InternalContext.SaveChanges() + 0x144 bytes
EntityFramework.dll!System.Data.Entity.Internal.LazyInternalContext.SaveChanges() + 0x36 bytes
EntityFramework.dll!System.Data.Entity.DbContext.SaveChanges() + 0x35 bytes
回答1:
From the stacktrace you showed it appears to me that the problem is in View Generation. Since you are using code first I would encourage you to try EF6 which contains performance improvements for view generation. For previous versions as a workaround you can pre-generate views (e.g. using EF Power Tools or a template I created http://visualstudiogallery.msdn.microsoft.com/ae7730ce-ddab-470f-8456-1b313cd2c44d). It will still take long to create the view but it will be at design time and not runtime.
来源:https://stackoverflow.com/questions/14315425/entity-framework-taking-a-lot-of-time-initializing-model