添加到表的System.Data.Entity.Infrastructure.DbUpdateException

时间:2017-11-24 21:00:36

标签: c# asp.net entity-framework

当我尝试将图片添加到数据库时,我收到错误

  

" InvalidOperationException:一个依赖属性   ReferentialConstraint映射到存储生成的列。柱:   '作业ID'"

我认为它试图将信息保存在job表中,而不是jobPic表中。我不确定如何解决这个问题。任何帮助将不胜感激。

// GET: jobPics/Create
    public ActionResult Create()
    {
        ViewBag.JobID = new SelectList(db.jobPics, "JobID", "Description");
        return View();
    }

    // POST: jobPics/Create
    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Create([Bind(Include = "JobID,Before,After")] jobPic jobPics)
    {
        if (ModelState.IsValid)
        {
            db.jobPics.Add(jobPics);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        ViewBag.JobID = new SelectList(db.jobPics, "JobID", "Description", jobPics.JobID);
        return View(jobPics);
    }

Database Diagram

0 个答案:

没有答案