使用 DTO 在对象关系映射器和数据访问层之间传输数据

发布于 2024-07-12 11:20:49 字数 60 浏览 7 评论 0原文

使用 DTO 在对象关系层和数据访问层之间传输数据是否有意义? 这种模式什么时候有用,什么时候它是反模式

Does it make sense to transfer data between Object-relational and Data Access Layer using DTO? When would this pattern be useful and when would it be an anti-pattern

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

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

发布评论

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

评论(1

人生戏 2024-07-19 11:20:49

当您想要将业务代码与数据库隔离时,它非常有用。 简单来说,DTO 是通过从数据库中进行选择来创建的,并且对 DTO 的更改由数据访问层转换回数据库。 在某些情况下,您甚至可以实现数据库供应商独立性(至少在代码的业务方面)。

常见的缺点是当您使用非常具体的 SQL 来处理复杂的联接、联合等或最大化性能时。 在这些情况下,让 DAL 允许某种“旁路”方法非常有用,您可以在其中发送动态 sql 或存储过程并取回数据。

It is very useful when you want to isolate your business code from your database. In very simple terms the DTO's are created by selecting from the database, and changes to the DTO are translated back to the database by the Data Access Layer. In some cases you can even achieve database vendor independence (at least on the business side of your code).

The common downside is when you have very specific SQL to adress complicated joins, unions, etc or to maximize performance. In these cases it is useful to have the DAL allow for some sort of "bypass" method where you send dynamic sql or a stored procedure and get the data back.

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