在事务中仅更新大型业务对象的 1 个字段的最佳方法是什么?

发布于 2024-09-15 05:11:49 字数 346 浏览 2 评论 0原文

我所处的情况是,我必须执行交易主详细信息记录(删除先前详细信息、插入新详细信息、更新主状态

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

现在我只需更新主表中的 1 个字段和详细信息表中的 4 个字段即可插入。

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

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

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. Master Business Object has 20
    fields
  2. Details Business Object
    has 4 fields only

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

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 ?

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

猫烠⑼条掵仅有一顆心 2024-09-22 05:11:49

我猜你的意思是公开这 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).

So in summary:

  • Make an update object only if its also a logical part of your Domain Model
  • Trust in your persistence layer to see what has changed.
策马西风 2024-09-22 05:11:49

使用这 4 个字段创建 DTO。 UI 会将此 DTO 发送到业务层,业务层将使用新值来修改业务对象。比你坚持修改后的业务对象。

Create DTO with those 4 fields. UI will send this DTO to business layer which will use new values to modify business object. Than you persist that modified business object.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文