开发者

Update model from view model

开发者 https://www.devze.com 2023-03-11 06:07 出处:网络
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 DT

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

精彩评论

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

关注公众号