在事务中仅更新大业务对象的 1 个字段的最佳方法是什么? [英] What is the best way to Update only 1 field of a big Business Object inside a transaction?

查看:20
本文介绍了在事务中仅更新大业务对象的 1 个字段的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须执行交易主详细记录(删除上一个详细信息,插入新详细信息,更新主状态)

I am in a situation where I have to perform a transaction master detail record (Drop prev details, insert new details, Update Master status)

  1. 主业务对象有 20字段
  2. 详细信息业务对象只有 4 个字段

现在我只需要更新主表中的 1 个字段和详细信息表中的 4 个字段以进行插入.

Now I have to update only 1 field in master table and 4 fields in details table for insert.

如果我初始化一个新的主对象,那么一个简单的更新就会浪费 19 个字段.我该怎么做才能有效地处理这种情况?

If I initialize a new master object, 19 fields are being wasted for a simple update. What do I do to efficiently handle this situation ?

我可以创建一个新对象并仅从我的主业务对象继承一个字段吗?如果您建议我使用 DTO 或具有继承性的东西,请给我一个工作示例.谢谢.

Can I make a new object and inherit only one field from my master business object ? Please give me a little working example if you advise me a DTO or something with inheritance. Thanks.

推荐答案

我猜你的意思是暴露这 4 个字段,而不是继承它们,因为你不能真正继承字段,只能继承一个类.

I guess you mean exposing those 4 fields, instead of inheriting them since you cannot really inherit fields, only a class.

您可以制作一个更小、更简单的更新对象",但只有在您的模型中逻辑上也存在这个较小的对象时,我才会这样做.理想情况下,您真的不想创建特殊对象来仅更新部分业务对象.相反,你的持久层的任务是足够聪明,知道哪些字段发生了变化并采取相应的行动(即只更新这些字段).

You could make a smaller, simpler 'update object', but I would only do so if this smaller object also exists logically in your model. Ideally, you really don't want to create special objects for updating only parts of your business objects. Instead, it's the task of your persistence layer to be smart enough to know which fields have changed and act accordingly (ie only update those fields).

总结:

  • 仅当更新对象也是域模型的逻辑部分时才创建更新对象
  • 相信你的持久层,看看发生了什么变化.

这篇关于在事务中仅更新大业务对象的 1 个字段的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆