使用实体框架,而忽略了一些特性更新实体

编程入门 行业动态 更新时间:2024-10-25 17:29:38
本文介绍了使用实体框架,而忽略了一些特性更新实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我跟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();

更多推荐

使用实体框架,而忽略了一些特性更新实体

本文发布于:2023-11-15 12:30:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1594459.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:实体   框架   特性   忽略了

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!