从6.0-beta1升级后,EF 6.0+中的空引用异常

时间:2014-03-24 13:37:37

标签: c# .net entity-framework

将项目从EF 6.0-beta1升级到EF 6.0-6.1(每个版本都会出现这种情况) 我得到例外:

    System.NullReferenceException: Object reference not set to an instance of an object.
   at         System.Data.Entity.Core.Mapping.ViewGeneration.Structures.TypeRestriction.AsUserString(StringBuilder builder, String blockAlias, Boolean skipIsNotNull)
   at System.Data.Entity.Core.Mapping.ViewGeneration.Structures.BoolExpression.AsUserStringVisitor.VisitTerm(TermExpr`1 expression)
   at System.Data.Entity.Core.Common.Utils.Boolean.TermExpr`1.Accept[T_Return](Visitor`2 visitor)
   at System.Data.Entity.Core.Mapping.ViewGeneration.Structures.BoolExpression.AsUserStringVisitor.VisitAndOr(TreeExpr`1 expression, ExprType kind)
   at System.Data.Entity.Core.Mapping.ViewGeneration.Structures.BoolExpression.AsUserStringVisitor.VisitAnd(AndExpr`1 expression)
   at System.Data.Entity.Core.Common.Utils.Boolean.AndExpr`1.Accept[T_Return](Visitor`2 visitor)
   at System.Data.Entity.Core.Mapping.ViewGeneration.Structures.BoolExpression.AsUserStringVisitor.VisitAndOr(TreeExpr`1 expression, ExprType kind)
   at System.Data.Entity.Core.Mapping.ViewGeneration.Structures.BoolExpression.AsUserStringVisitor.VisitOr(OrExpr`1 expression)
   at System.Data.Entity.Core.Common.Utils.Boolean.OrExpr`1.Accept[T_Return](Visitor`2 visitor)
   at System.Data.Entity.Core.Mapping.ViewGeneration.Structures.BoolExpression.AsUserStringVisitor.AsUserString(BoolExpr`1 expression, StringBuilder builder, String blockAlias)
   at System.Data.Entity.Core.Mapping.ViewGeneration.Structures.BoolExpression.AsUserString(StringBuilder builder, String blockAlias, Boolean writeRoundtrippingMessage)
   at System.Data.Entity.Core.Mapping.ViewGeneration.Validation.RewritingValidator.EntityConfigurationToUserString(BoolExpression condition, StringBuilder builder, Boolean writeRoundTrippingMessage)
   at System.Data.Entity.Core.Mapping.ViewGeneration.Validation.RewritingValidator.EntityConfigurationToUserString(BoolExpression condition, StringBuilder builder)
   at System.Data.Entity.Core.Mapping.ViewGeneration.QueryRewriting.QueryRewriter.AddElseDefaultToCaseStatement(MemberPath currentPath, CaseStatement caseStatement, List`1 domain, CellTreeNode rightDomainQuery, Tile`1 unionCaseRewriting)
   at System.Data.Entity.Core.Mapping.ViewGeneration.QueryRewriting.QueryRewriter.GenerateCaseStatements(IEnumerable`1 members, HashSet`1 outputUsedViews)
   at System.Data.Entity.Core.Mapping.ViewGeneration.QueryRewriting.QueryRewriter.GenerateViewComponents()
   at System.Data.Entity.Core.Mapping.ViewGeneration.ViewGenerator.GenerateViewsForExtentAndType(EdmType generatedType, ViewgenContext context, CqlIdentifiers identifiers, KeyToListMap`2 views, ViewGenMode mode)
   at System.Data.Entity.Core.Mapping.ViewGeneration.ViewGenerator.GenerateDirectionalViewsForExtent(ViewTarget viewTarget, EntitySetBase extent, CqlIdentifiers identifiers, KeyToListMap`2 views)
   at System.Data.Entity.Core.Mapping.ViewGeneration.ViewGenerator.GenerateDirectionalViews(ViewTarget viewTarget, CqlIdentifiers identifiers, KeyToListMap`2 views)
   at System.Data.Entity.Core.Mapping.ViewGeneration.ViewGenerator.GenerateAllBidirectionalViews(KeyToListMap`2 views, CqlIdentifiers identifiers)
   at System.Data.Entity.Core.Mapping.ViewGeneration.ViewgenGatekeeper.GenerateViewsFromCells(List`1 cells, ConfigViewGenerator config, CqlIdentifiers identifiers, EntityContainerMapping containerMapping)
   at System.Data.Entity.Core.Mapping.ViewGeneration.ViewgenGatekeeper.GenerateViewsFromMapping(EntityContainerMapping containerMapping, ConfigViewGenerator config)
   at System.Data.Entity.Core.Mapping.StorageMappingItemCollection.ViewDictionary.SerializedGenerateViews(EntityContainerMapping entityContainerMap, Dictionary`2 resultDictionary)
   at System.Data.Entity.Core.Mapping.StorageMappingItemCollection.ViewDictionary.SerializedGetGeneratedViews(EntityContainer container)
   at System.Data.Entity.Core.Common.Utils.Memoizer`2.<>c__DisplayClass2.<Evaluate>b__0()
   at System.Data.Entity.Core.Common.Utils.Memoizer`2.Result.GetValue()
   at System.Data.Entity.Core.Common.Utils.Memoizer`2.Evaluate(TArg arg)
   at System.Data.Entity.Core.Mapping.StorageMappingItemCollection.ViewDictionary.GetGeneratedView(EntitySetBase extent, MetadataWorkspace workspace, StorageMappingItemCollection storageMappingItemCollection)
   at System.Data.Entity.Core.Mapping.StorageMappingItemCollection.GetGeneratedView(EntitySetBase extent, MetadataWorkspace workspace)
   at System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.GetGeneratedView(EntitySetBase extent)
   at System.Data.Entity.Core.Query.PlanCompiler.PreProcessor.ExpandView(ScanTableOp scanTableOp, IsOfOp& typeFilter)
   at System.Data.Entity.Core.Query.PlanCompiler.PreProcessor.ProcessScanTable(Node scanTableNode, ScanTableOp scanTableOp, IsOfOp& typeFilter)
   at System.Data.Entity.Core.Query.PlanCompiler.PreProcessor.Visit(ScanTableOp op, Node n)
   at System.Data.Entity.Core.Query.InternalTrees.ScanTableOp.Accept[TResultType](BasicOpVisitorOfT`1 v, Node n)
   at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n)
   at System.Data.Entity.Core.Query.PlanCompiler.SubqueryTrackingVisitor.VisitChildren(Node n)
   at System.Data.Entity.Core.Query.PlanCompiler.SubqueryTrackingVisitor.VisitRelOpDefault(RelOp op, Node n)
   at System.Data.Entity.Core.Query.PlanCompiler.PreProcessor.Visit(ProjectOp op, Node n)
   at System.Data.Entity.Core.Query.InternalTrees.ProjectOp.Accept[TResultType](BasicOpVisitorOfT`1 v, Node n)
   at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n)
   at System.Data.Entity.Core.Query.PlanCompiler.SubqueryTrackingVisitor.VisitChildren(Node n)
   at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfNode.VisitDefault(Node n)
   at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfNode.VisitPhysicalOpDefault(PhysicalOp op, Node n)
   at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.Visit(PhysicalProjectOp op, Node n)
   at System.Data.Entity.Core.Query.InternalTrees.PhysicalProjectOp.Accept[TResultType](BasicOpVisitorOfT`1 v, Node n)
   at System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n)
   at System.Data.Entity.Core.Query.PlanCompiler.PreProcessor.Process(Dictionary`2& tvfResultKeys)
   at System.Data.Entity.Core.Query.PlanCompiler.PreProcessor.Process(PlanCompiler planCompilerState, StructuredTypeInfo& typeInfo, Dictionary`2& tvfResultKeys)
   at System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Compile(List`1& providerCommands, ColumnMap& resultColumnMap, Int32& columnCount, Set`1& entitySets)
   at System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Compile(DbCommandTree ctree, List`1& providerCommands, ColumnMap& resultColumnMap, Int32& columnCount, Set`1& entitySets)
   at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition..ctor(DbProviderFactory storeProviderFactory, DbCommandTree commandTree, DbInterceptionContext interceptionContext, IDbDependencyResolver resolver, BridgeDataReaderFactory bridgeDataReaderFactory, ColumnMapFactory columnMapFactory)
   at System.Data.Entity.Core.EntityClient.Internal.EntityProviderServices.CreateCommandDefinition(DbProviderFactory storeProviderFactory, DbCommandTree commandTree, DbInterceptionContext interceptionContext, IDbDependencyResolver resolver)
   at System.Data.Entity.Core.EntityClient.Internal.EntityProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree, DbInterceptionContext interceptionContext)
   at System.Data.Entity.Core.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree, DbInterceptionContext interceptionContext)
   at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlanFactory.CreateCommandDefinition(ObjectContext context, DbQueryCommandTree tree)
   at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlanFactory.Prepare(ObjectContext context, DbQueryCommandTree tree, Type elementType, MergeOption mergeOption, Boolean streaming, Span span, IEnumerable`1 compiledQueryParameters, AliasGenerator aliasGenerator)
   at System.Data.Entity.Core.Objects.EntitySqlQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__6()
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__5()
   at System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute[TResult](Func`1 operation)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
   at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()

尝试从任何DbSet获取数据时&lt;&gt;在上下文中。 我正在检查这些DBSets为null - 它们不是null。我还尝试搜索stackoverflow和其他来源 - 无法找到适合此问题的解决方案。 还有一个 - 数据库创建很好,所有表都是在Sql Server和SqlCE上成功创建的。

提前感谢。

0 个答案:

没有答案