How can I update my entities with a json changeset?

Given optimistic concurrency using a version property and a json rest-service with a client that returns changesets consisting of the Id, Version and changed properties only, how can I update my server-side entity? What I wanted to do was deserialize my json into a detatched entity and then use the ISession.Merge method to update my entity. However, my detached entity will have null-values for a lot of properties, and my entity will be updated with all of these if I call merge, which is not what I want. If there is a way to tell merge to ignore properties that are null and keep any corresponding non-null values from the persisted entity that would solve my problem. If there is no way to configure the behaviour for merge, I could of course get the persisted entity and implement my own merging method using reflection. The problem with this approach is that it requires that I first query the db for the entity and then update it, whereas the merge method should do this as one operation unless I am mistaken. You might ask why I want to pass only changesets instead of the complete entity. It is because it allows me to send minimal data and it also indicates explicity what the user is trying to change, which I can use for testing that users rights. If it isn't possible to do this within the bounds of nhibernate, how would you proceed?
i would take the reflection route. it takes one more roundtrip but saves you a lot of hassle. i think you can tweak merge with a custom interceptor but i think it's not worth it until proven othrwise

以上就是How can I update my entities with a json changeset?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JSON 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准