本文介绍了使用实体框架,而忽略了一些特性更新实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我跟asp的MVC 4.工作我有使用编辑方法来更新我的持久存储,但我想忽略某些列。
I am working with asp mvc 4. I have to update my persistence store using an edit method, but I want to ignore some columns.
我已经在这里找到了一些答案,但他们并没有为我工作(我想)。
I had found some answers here, but they weren't working for me (I suppose).
下面是我的方法:
[HttpPost] public ActionResult Edit(Candidat candidat) { ProcRecDB _db = new ProcRecDB(); // from DbContext if (ModelState.IsValid) { _db.Entry(candidat).State = EntityState.Modified; _db.SaveChanges(); return RedirectToAction("Index"); } return View(candidat); }候选模型有10个属性;我怎么会忽略其中的一些?
The Candidate model has 10 properties; how would I ignore some of them?
推荐答案如果您使用EF 5,您可以标记一个属性作为修改了其被标记为后不修改
If your using EF 5, you can mark a property as not modified after its been marked as modified
_db.Entry(candidat).State = EntityState.Modified; // Ignore changes to the value of SomeProperty _db.Entry(candidat).Property("SomeProperty").IsModified = false; _db.SaveChanges();更多推荐
使用实体框架,而忽略了一些特性更新实体
发布评论