我使用EF4 DbContext为ASP.NET MVC应用程序提供模型.我使用viewmodels向视图提供数据,使用Automapper执行EF POCO和viewmodel之间的映射. Automapper做得很好,但在viewmodel发回控制器进行更新后,我不清楚使用它的最佳方法.
我的想法是使用viewmodel中包含的密钥获取POCO对象.然后,我想使用Automapper使用viewmodel中的数据更新POCO:
[HttpPost] public ActionResult Edit(PatientView viewmodel) { Patient patient = db.Patients.Find(viewmodel.Id); patient = Mapper.Map<viewmodel,Patient>(viewmodel,patient); ... db.SaveChanges(); return RedirectToAction("Index"); }
两个问题:
> Find()方法返回一个代理而不是一个导致Automapper投诉的POCO.我如何获得POCO而不是代理?
>这是执行更新的最佳做法吗?
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。