开发者

Update model from view model

What开发者_如何学Go's the usual way to update a NHibernate entity from a view model?

I have a view model editor where all of my data is displayed, which is fetched via a repository that returns a DTO. The DTO properties are then mapped to my view model properties. I could update my entity if I fetched it again, updated the select property required

Is there a better way?


You could use AutoMapper, which is especially easy if the view models closely match the entities.

How to simply map an NHibernate ISet to IList using AutoMapper


My usual approach is to have an EditXViewModel which handles change tracking for XViewModel and includes a SaveCommand which does the actual entity update. This ensures users can undo changes made without having to remember what they were in the database (it also cuts down on the number of transactions).

The following articles were immensely helpful when I started down this same path:

  • Nhibernate and WPF: ViewModels and Views
  • Building a Desktop To-Do Application with NHibernate
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜