0

[编辑]:该应用程序在我的本地运行良好,但不会在AppHarbor运行。在我的网站的初始加载时,我会在另一个问题中提到这个错误,如果我重新加载页面,那么我会得到下面提到的错误。正如 appharbor 的管理员所提到的,他们正在解决新遗物和 ninject 的问题。但我不太确定我的第二个错误是否仍然与 appharbor 的新遗物问题有关。Devtalk.EF.CodeFirst.DontDropDbJustCreateTablesIfModelChanged 是否与 EF 4.3 一起正常工作?我只是等待他们的更新吗?

[InvalidOperationException: The object cannot be detached because it is not attached to the ObjectStateManager.]
   at System.Data.Objects.ObjectContext.Detach(Object entity, EntitySet expectedEntitySet)
   at System.Data.Objects.ObjectContext.Detach(Object entity)
   at Devtalk.EF.CodeFirst.DontDropDbJustCreateTablesIfModelChanged`1.SaveModelHashToDatabase(T context, String modelHash, ObjectContext objectContext)
   at Devtalk.EF.CodeFirst.DontDropDbJustCreateTablesIfModelChanged`1.InitializeDatabase(T context)
   at System.Data.Entity.Database.<>c__DisplayClass2`1.<SetInitializerInternal>b__0(DbContext c)
   at System.Data.Entity.Internal.InternalContext.<>c__DisplayClass8.<PerformDatabaseInitialization>b__6()
   at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
   at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
   at System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c)
   at System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input)
   at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action)
   at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
   at System.Data.Entity.Internal.InternalContext.Initialize()
   at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
   at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
   at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
   at System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
   at System.Linq.Queryable.Where[TSource](IQueryable`1 source, Expression`1 predicate)
   at Core.Repository`2.Find(Expression`1 predicate) in d:\temp\2otuf0q2.xtn\input\Domain\Core\Repository.cs:line 52
   at Data.RegistrantRepository.GetAllRegistrant() in d:\temp\2otuf0q2.xtn\input\Data\Data\RegistrantRepository.cs:line 20
   at IPOD.Controllers.HomeController.Index() in d:\temp\2otuf0q2.xtn\input\IPOD\Controllers\HomeController.cs:line 28
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
   at System.Web.Mvc.Controller.ExecuteCore()
   at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
   at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)
   at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<>c__DisplayClassb.<BeginProcessRequest>b__5()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
   at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag)
   at System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag)
   at System.Web.Mvc.MvcHandler.<>c__DisplayClasse.<EndProcessRequest>b__d()
   at System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f)
   at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action)
   at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
4

1 回答 1

1

对我来说,初始化程序似乎正在尝试更新 EdmMetadata 表 - 至少这是我从中推断出来的:

Devtalk.EF.CodeFirst.DontDropDbJustCreateTablesIfModelChanged`1.SaveModelHashToDatabase(T context, String modelHash, ObjectContext objectContext) 

在 EF 4.3 中,不会创建 EdmMeatadata 表(如果您的数据库中有一个并且模型没有更改,则将使用它 - 即当您从 4.1/4.2 升级到 4.3+ 时 - 有关更多详细信息,请参阅:http:// blog.oneunicorn.com/2012/01/13/ef-4-3-beta-1-what-happened-to-that-edmmetadata-table/

在 4.3 世界中,如果您的模型发生更改并且您需要更新数据库但不想实际删除并重新创建它,您希望使用迁移。看看这个演练:http: //blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-code-based-migrations-walkthrough.aspx

于 2012-04-08T03:37:35.633 回答