“ EntityFrameworkDynamicProxies-Appointments”的元数据无效

时间:2019-05-12 08:46:18

标签: entity-framework asp.net-mvc-5 automapper

showing result here the error comes

使用源到目标的映射时出现此错误。

AppointmentStatuses =“ EntityFrameworkDynamicProxies-Appointments”的元数据无效。如果要调试小型转储,则可以通过使用堆收集新的小型转储并再次评估表达式来解决此问题。

只有在代码到达

时才会出现
public ActionResult Approve(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            var AppointmentRequest = db.Appointments.Where(p => p.AppointmentID == id).Include(m => m.VisitRequests).Include(m => m.AppointmentStatuses).FirstOrDefault();
            if (AppointmentRequest == null)
            {
                return HttpNotFound();
            }

            if (AppointmentRequest.AppointmentTypeID != 2 && !rp.IsUserInRole(UserName, "ApproveOfficialAppointment"))
            {
                TempData["error"] = "لا تملك صلاحية اعتماد المواعيد الخاصة والرسمية";
                return RedirectToAction("Requests");
            }
            if (AppointmentRequest.AppointmentTypeID == 2 && !rp.IsUserInRole(UserName, "ApproveAppointment"))
            {
                TempData["error"] = "لا تملك صلاحية اعتماد المواعيد غيرالرسمية";
                return RedirectToAction("Requests");
            }

            var vmodel = Mapper.Map<ApproveAppointmentViewModel>(AppointmentRequest);
            vmodel.AppointmentStatuses = new List<ApproveAppointmentStatusViewModel> { vmodel.AppointmentStatuses.OrderByDescending(s => s.ValidFrom).FirstOrDefault() };
            return View(vmodel);

        }

此行出现错误

  var vmodel = Mapper.Map<ApproveAppointmentViewModel>(AppointmentRequest);

在AppointmentRequest这一行具有所有数据之前,但在到达Mapping行时,错误伴随stackoverflow异常。

0 个答案:

没有答案