收集被修改;枚举操作可能无法执行。实体框架5除了本地

时间:2013-07-16 20:08:00

标签: entity-framework entity-framework-5

我收到错误“收集已修改;枚举操作可能无法执行。”在所有环境Dev,QA和Production中,但不在本地开发机器上。如果我将本地应用程序指向QA数据库,它可以正常工作但指向QA数据库的QA应用程序会收到此错误。

在我的本地机器上,我使用IIS 6安装了Windows 7以及所有其他环境DEV,QA和Production。

我不知道哪条线路出现错误,因为我在本地计算机的调试模式下没有收到此错误。但这里是代码和堆栈跟踪。

foreach (var videoTag in videoModel.VideoTags.ToList())
        {
            if (videoTag.TagName != null)
            {
                // if tag already exists continue to next tag
                if (video.VideoTags.Any(x => x.TagName == videoTag.TagName)) continue;

                var newVideoTag = _entityFactory.Create<VideoTag>();
                var userName = Util.GetCurrentUserName();
                newVideoTag.TaggedBy = userName;
                newVideoTag.TaggedOn = DateTime.Now;

                var tag = _tagRepository().Get(x => x.TagName == videoTag.TagName);
                if (tag == null)
                {
                    tag = _entityFactory.Create<Tag>();
                    tag.TagName = videoTag.TagName;
                }
                newVideoTag.Tag = (Tag)tag;
                newVideoTag.TagName = videoTag.TagName;
                newVideoTag.VideoId = video.VideoId;

                video.VideoTags.Add(newVideoTag);
            }
        }

        // remove tags if removed
        var videoTagToRemove = video.VideoTags.Where(videoTag => !videoModel.VideoTags.Any(x => x.TagName == videoTag.TagName)).ToList();
        foreach (var videoTag in videoTagToRemove.ToList())
        {
            _videoRepository().DeleteVideoTag(videoTag);
            //video.VideoTags.Remove(videoTag);
        }

        var optStatus = _videoRepository().Update(video);
        if (!optStatus.Status)
        {
            throw new Exception(optStatus.ExceptionMessage); // line no  309
        }

堆栈跟踪: 位于:E:\ TFS \ Projects \ Ford \ FordTube \ Dev \ Source \ Ford.FordTube \ Web.UI \ Controllers \ VideoController.cs中的FordTube.Web.UI.Controllers.VideoController.UpdateVideo(VideoModel videoModel):lambda_method的第309行(闭包,ControllerBase,Object [])在System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase控制器,Object []参数)处于System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext,IDictionary 2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary 2个参数)System.Web.Mvc.Async.AsyncControllerActionInvoker。&lt;&gt; c_ DisplayClass42.b _41()在System.Web.Mvc.Async.AsyncResultWrapper。&lt;&gt; c_ DisplayClass8 1.<BeginSynchronous>b__7(IAsyncResult _) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult 1.End()在System.Web.Mvc.Async.AsyncControllerActionInvoker的System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)中。&lt;&gt; c _DisplayClass37。&lt; &gt; c_ DisplayClass39.b _33()在System.Web上的System.Web.Mvc.Async.AsyncControllerActionInvoker。&lt;&gt; c_ DisplayClass4f.b _49()。 Mvc.Async.AsyncControllerActionI System.Web.Mvc上的System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult 1.End() at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<>c__DisplayClass2a.<BeginInvokeAction>b__20() at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult 1.End()中的nvoker。&lt;&gt; c_ DisplayClass37.b _36(IAsyncResult asyncResult) System.Web.Mvc.Asse.AsyncResultWrapper上的System.Web.Mvc.Controller。&lt;&gt; c_ DisplayClass1d.b _18(IAsyncResult asyncResult)中的.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)。 &lt;&gt; c_ DisplayClass4.b _3(IAsyncResult ar)在System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult 1.End() at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult 1.End()在System.Web.Mvc.Controller上.EndExecute(IAsyncResult asyncResult)在System.Web.Mvc.MvcHandler的System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult)。&lt;&gt; c_ DisplayClass8.b System.Web.Mvc.Async.AsyncResultWrapper上的System.Web.Mvc.Async.AsyncResultWrapper。 _3(IAsyncResult asyncResult)。&lt;&gt; c_ DisplayClass4.b _3(IAsyncResult ar) .WrappedAsyncResult`1.End()在System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult async)结果)在System.Web.HttpApplication.ExecuteStep的System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()上的System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult结果)中(IExecutionStep步骤,布尔&amp;已完成(同步)

0 个答案:

没有答案