什么是更新事务中只有1个大业务对象的领域中的最佳方式是什么? [英] What is the best way to Update only 1 field of a big Business Object inside a transaction?

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

问题描述

我在一个情况下,我不得不进行交易主详细记录(下拉$ P $光伏细节,插入新的细节,更新主状态

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

现在我只更新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天全站免登陆