enter image description here

An entity entity cannot be referenced by multiple instances of the IEntityChangeTracker interface. When saving

[HttpPost] public ActionResult Save(RegisterApplicationForm doc) { var entity = new sovadb001Entities0(); order norder = new order(); if(doc.fileNames!=null) foreach (var fileName in doc.fileNames) { //string fileName = System.IO.Path.GetFileName(UploadedFile.FileName); document ndoc = new document(); ndoc.conuntOfSymbols = 1; System.IO.FileInfo fi = new System.IO.FileInfo(Server.MapPath("~/Content/Temporary/" + fileName)); ndoc.dataType =fi.Extension; ndoc.pathToDoc = fi.Directory.FullName; ndoc.order = norder; ndoc.idOrder = norder.IdOrder; //DataBase.AddDoc(ndoc); entity.documents.Add(ndoc); norder.documents.Add(ndoc); Server.MapPath("~/Content/file" + fileName).ToString(); System.IO.File.Move(Server.MapPath("~/Content/Temporary/" + fileName), Server.MapPath("~/Content/file/"+fileName)); //using (FileStream fs = new FileStream("~/Content/Temporary/" + fileName, FileMode.Open)) { // using(FileStream fsw=new FileStream("~/Content/file/"+fileName,FileMode.CreateNew)){ // ; // fs // } //} } foreach (var spec in doc.spec) { documentSpecialization ndocSpec = new documentSpecialization(); ndocSpec.order = norder; ndocSpec.IdOrder = norder.IdOrder; ndocSpec.IdSpecialization = DataBase.GetSpecialization(spec).IdSpecialization; ndocSpec.specialization = DataBase.GetSpecialization(spec); //DataBase.AddDocSpec(ndocSpec); entity.documentSpecializations.Add(ndocSpec); norder.documentSpecializations.Add(ndocSpec); } norder.dateOfCompletion = DateTime.Now; norder.name = doc.name; norder.description = doc.description; norder.idDone = false; //DataBase.AddApplication(norder); entity.orders.Add(norder); return RedirectToAction("Index","Home"); // } }' 

An error occurs in the entity.documentSpecializations.Add(ndocSpec); method entity.documentSpecializations.Add(ndocSpec);

System.IO.FileNotFoundException not processed by user code HResult = -2147024894 Message = File 'C: \ Users \ Oleksandr \ Documents \ Visual Studio 2012 \ Projects \ SovaTranslate_001 \ SovaTranslate_001 \ Content \ Temporary \ 1O45e0euv0o.jpg' could not be found. Source = mscorlib FileName = C: \ Users \ Oleksandr \ Documents \ Visual Studio 2012 \ Projects \ SovaTranslate_001 \ SovaTranslate_001 \ Content \ Temporary \ 1O45e0euv0o.jpg StackTrace: in System.IO .__ Error.WinIOError (Int32 errorCode, String traceFirePath)) .IO.File.InternalMove (String sourceFileName, String destFileName, Boolean checkHost) in System.IO.File.Move (String sourceFileName, String destFileName) in SovaTranslate_001.Controllers.ApplicationController. \ Documents \ Visual Studio 2012 \ Projects \ SovaTranslate_001 \ SovaTranslate_001 \ Controllers \ ApplicationController.cs: line 76 in lambda_method (Closure, ControllerBase, Object []) in System.Web.Mvc.ActionMethodDispatcher.Execute (ControllerBase controller, Object []] ) in System.Web.Mvc.ReflectedActionDescriptor.Execute (ControllerContext controllerContext, IDictionary 2 parameters) в System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary 2 parameters) в System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary 2 parameters) в System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() в System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8 1.b__7 (the IAsyncResult _) in System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End () in System.Web.Mvc.Async AsyncResultWrapper.End [TResult] (IAsyncResult asyncResult, Object tag) in System.Web.M.c.v.yn.Async.AsyncControllerActionInvoker.isEndInvokeActionMethod (IAsyncResult asyncResult) in is iscs in ise is in. Is iscs in ise is in. Is iscs in ise is in. Is iscs in ise is in. Is iscs in is iscs in ises () in System.Web.Mvc.Async.AsyncControllerActionInvoker. <> c__DisplayClass4f.b__49 () InnerException:

Closed due to the fact that off-topic party PashaPash 15 May '16 at 10:10 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - PashaPash
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Clearly formulate your question. Give the stack trace. - iramm
  • Put your code in the tyr{} catch{} block, then post an error. - SᴇM
  • Why, if the error is the same, just the program will continue to work. - Sasha Sushko
  • one
    The error explicitly states that the file in `Content \ Temporary` that you are trying to move does not exist. EF and most of the code in question is not related to the error - look for the problem in the part of the code that this file should create. - PashaPash

0