2014-08-29 34 views
0

我使用Entity Framework,剛剛更新來自數據庫的一些改變,然後來到翻過這個錯誤:Problem in mapping fragments starting at lines 903, 1239:Two entities with possibly different keys are mapped to the same row. Ensure these two mapping fragments map both ends of the AssociationSet to the corresponding columns.實體框架的實體不同的鍵映射到同一行

我理解這個問題,但是,我不知道是什麼違規表是。該數據庫有50多個表格,並且它們之間有數百個關係。我不知道從哪裏開始。堆棧跟蹤:

[MappingException: 
Tracker.msl(903,10) : error 3034: Problem in mapping fragments starting at lines 903, 1239:Two entities with possibly different keys are mapped to the same row. Ensure these two mapping fragments map both ends of the AssociationSet to the corresponding columns. 
] 
    System.Data.Entity.Core.Mapping.ViewDictionary.SerializedGenerateViews(EntityContainerMapping entityContainerMap, Dictionary`2 resultDictionary) +193 
    System.Data.Entity.Core.Mapping.ViewDictionary.SerializedGetGeneratedViews(EntityContainer container) +327 
    System.Data.Entity.Core.Common.Utils.<>c__DisplayClass2.<Evaluate>b__0() +50 
    System.Data.Entity.Core.Common.Utils.Result.GetValue() +154 
    System.Data.Entity.Core.Common.Utils.Memoizer`2.Evaluate(TArg arg) +498 
    System.Data.Entity.Core.Mapping.ViewDictionary.GetGeneratedView(EntitySetBase extent, MetadataWorkspace workspace, StorageMappingItemCollection storageMappingItemCollection) +1596 
    System.Data.Entity.Core.Mapping.StorageMappingItemCollection.GetGeneratedView(EntitySetBase extent, MetadataWorkspace workspace) +62 
    System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.GetGeneratedView(EntitySetBase extent) +128 
    System.Data.Entity.Core.Query.PlanCompiler.PreProcessor.ExpandView(ScanTableOp scanTableOp, IsOfOp& typeFilter) +657 
    System.Data.Entity.Core.Query.PlanCompiler.PreProcessor.ProcessScanTable(Node scanTableNode, ScanTableOp scanTableOp, IsOfOp& typeFilter) +229 
    System.Data.Entity.Core.Query.PlanCompiler.PreProcessor.Visit(ScanTableOp op, Node n) +57 
    System.Data.Entity.Core.Query.InternalTrees.ScanTableOp.Accept(BasicOpVisitorOfT`1 v, Node n) +47 
    System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n) +121 
    System.Data.Entity.Core.Query.PlanCompiler.SubqueryTrackingVisitor.VisitChildren(Node n) +139 
    System.Data.Entity.Core.Query.PlanCompiler.SubqueryTrackingVisitor.VisitRelOpDefault(RelOp op, Node n) +62 
    System.Data.Entity.Core.Query.PlanCompiler.PreProcessor.Visit(FilterOp op, Node n) +295 
    System.Data.Entity.Core.Query.InternalTrees.FilterOp.Accept(BasicOpVisitorOfT`1 v, Node n) +47 
    System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n) +121 
    System.Data.Entity.Core.Query.PlanCompiler.SubqueryTrackingVisitor.VisitChildren(Node n) +139 
    System.Data.Entity.Core.Query.PlanCompiler.SubqueryTrackingVisitor.VisitRelOpDefault(RelOp op, Node n) +62 
    System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.VisitSortOp(SortBaseOp op, Node n) +47 
    System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.Visit(ConstrainedSortOp op, Node n) +47 
    System.Data.Entity.Core.Query.InternalTrees.ConstrainedSortOp.Accept(BasicOpVisitorOfT`1 v, Node n) +47 
    System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n) +121 
    System.Data.Entity.Core.Query.PlanCompiler.SubqueryTrackingVisitor.VisitChildren(Node n) +139 
    System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfNode.VisitDefault(Node n) +39 
    System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfNode.VisitPhysicalOpDefault(PhysicalOp op, Node n) +44 
    System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.Visit(PhysicalProjectOp op, Node n) +47 
    System.Data.Entity.Core.Query.InternalTrees.PhysicalProjectOp.Accept(BasicOpVisitorOfT`1 v, Node n) +47 
    System.Data.Entity.Core.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n) +121 
    System.Data.Entity.Core.Query.PlanCompiler.PreProcessor.Process(Dictionary`2& tvfResultKeys) +112 
    System.Data.Entity.Core.Query.PlanCompiler.PreProcessor.Process(PlanCompiler planCompilerState, StructuredTypeInfo& typeInfo, Dictionary`2& tvfResultKeys) +93 
    System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Compile(List`1& providerCommands, ColumnMap& resultColumnMap, Int32& columnCount, Set`1& entitySets) +170 
    System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Compile(DbCommandTree ctree, List`1& providerCommands, ColumnMap& resultColumnMap, Int32& columnCount, Set`1& entitySets) +111 
    System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition..ctor(DbProviderFactory storeProviderFactory, DbCommandTree commandTree, DbInterceptionContext interceptionContext, IDbDependencyResolver resolver, BridgeDataReaderFactory bridgeDataReaderFactory, ColumnMapFactory columnMapFactory) +647 

[EntityCommandCompilationException: An error occurred while preparing the command definition. See the inner exception for details.] 
    System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition..ctor(DbProviderFactory storeProviderFactory, DbCommandTree commandTree, DbInterceptionContext interceptionContext, IDbDependencyResolver resolver, BridgeDataReaderFactory bridgeDataReaderFactory, ColumnMapFactory columnMapFactory) +2623 
    System.Data.Entity.Core.EntityClient.Internal.EntityProviderServices.CreateCommandDefinition(DbProviderFactory storeProviderFactory, DbCommandTree commandTree, DbInterceptionContext interceptionContext, IDbDependencyResolver resolver) +68 
    System.Data.Entity.Core.EntityClient.Internal.EntityProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree, DbInterceptionContext interceptionContext) +151 
    System.Data.Entity.Core.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree, DbInterceptionContext interceptionContext) +220 
    System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlanFactory.CreateCommandDefinition(ObjectContext context, DbQueryCommandTree tree) +210 
    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) +255 
    System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption) +2430 
    System.Data.Entity.Core.Objects.<>c__DisplayClass7.<GetResults>b__6() +83 
    System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) +448 
    System.Data.Entity.Core.Objects.<>c__DisplayClass7.<GetResults>b__5() +271 
    System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func`1 operation) +251 
    System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) +648 
    System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0() +68 
    System.Data.Entity.Internal.LazyEnumerator`1.MoveNext() +68 
    System.Linq.Enumerable.SingleOrDefault(IEnumerable`1 source) +4098209 
    System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__2(IEnumerable`1 sequence) +83 
    System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.ExecuteSingle(IEnumerable`1 query, Expression queryRoot) +107 
    System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute(Expression expression) +197 
    System.Data.Entity.Internal.Linq.DbQueryProvider.Execute(Expression expression) +155 
    System.Linq.Queryable.SingleOrDefault(IQueryable`1 source, Expression`1 predicate) +287 
    Tracker.Implementations.UserDetails.Tracker.Infrastructure.IUserDetails.getUser(String Email) +550 
    TrackerV3MVC.Controllers.HomeController.Index() in c:\WorkSpace\Entire Solution\TrackerV3MVC\Controllers\HomeController.cs:32 
    lambda_method(Closure , ControllerBase , Object[]) +101 
    System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14 
    System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +211 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27 
    System.Web.Mvc.Async.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() +28 
    System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10 
    System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57 
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +48 
    System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +57 
    System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +223 
    System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) +10 
    System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57 
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +48 
    System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +24 
    System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +102 
    System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57 
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +43 
    System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14 
    System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23 
    System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62 
    System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +57 
    System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23 
    System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62 
    System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +47 
    System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10 
    System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +25 
    System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23 
    System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62 
    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +47 
    System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9 
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9514928 
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155 
+0

你試圖刪除所有表並重新添加它們? 'update'功能不能很好地工作 – Vland 2014-08-29 09:45:28

+0

嗨。我其實只是想知道的是,有沒有辦法可以獲得有關此錯誤的更多信息?我至少需要知道什麼表導致了這一點。我知道這個問題的解決方案,但我需要知道它來自哪裏。我嘗試過製作中斷點並加入DBCOntext,但沒有成功。由於某種原因,我不能刪除並重新創建它。一些問題在應用程序中處理,不一定在數據庫設計中。顯然不是最好的決定,但是這個項目是在4個月內到期,下週到期,而我剛剛遇到了這個問題。 – 2014-08-29 09:51:53

+0

你打開了'edmx'文件並導航到冒犯的線?他們看起來怎麼樣? – Vland 2014-08-29 10:05:44

回答

1

有時Entity Framework未給出關於錯誤的準確指示。而update model工具不能正常工作......

在這些情況下,我通常會清除edmx文件(刪除所有表格)並重新添加它們。

如果這是不可能的,打開你的edmx文件(作爲xml文件)並導航到錯誤中指定的線路,你可能會發現你的煩惱之源