Poco 与 ORM 的“大"优势是什么? [英] What are the 'big' advantages to have Poco with ORM?

查看:23
本文介绍了Poco 与 ORM 的“大"优势是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想到的一个优势是,如果您使用 Poco 类进行 Orm 映射,那么您可以轻松地从一个 ORM 切换到另一个,如果两者都支持 Poco.

One advantage that comes to my mind is, if you use Poco classes for Orm mapping, you can easily switch from one ORM to another, if both support Poco.

有一个没有 Poco 支持的 ORM,例如映射是使用 DataObjects.Net Orm 之类的属性完成的,对我来说不是问题,Poco 支持的 Orms 及其生成的代理实体也是如此,您必须意识到实体实际上是绑定到某些上下文/会话的 DAO 对象,例如序列化是一个问题,等等.

Having an ORM with no Poco support, e.g. mappings are done with attributes like the DataObjects.Net Orm, is not an issue for me, as also with Poco-supported Orms and theirs generated proxy entities, you have to be aware that entities are actually DAO objects bound to some context/session, e.g. serializing is a problem, etc..

推荐答案

POCO 一切都与松耦合和可测试性有关.

POCO it's all about loose coupling and testability.

因此,当您进行 POCO 时,您可以单独测试您的领域模型(例如,如果您正在执行 DDD).您不必担心它是如何持久化的.您不需要存根上下文/会话来测试您的域.

So when you are doing POCO you can test your Domain Model (if your're doing DDD for example) in isolation. You don't have to bother about how it is persisted. You don't need to stub contexts/sessions to test your domain.

另一个优点是抽象泄漏更少.因为持久性问题不会被推到领域层.因此,您正在执行 SRP 原则.

Another advantage is that there is less leaky abstractions. Because persistance concerns are not pushed to domain layer. So you are enforcing the SRP principle.

我能看到的第三个优势是,对领域模型进行 POCO 会更加进化和灵活.与将新功能耦合到持久性相比,您可以更轻松地添加新功能.

The third advantage I can see is that doing POCO your Domain Model is more evolutive and flexible. You can add new features easier than if it was coupled to the persistance.

例如,我在执行 DDD 时使用 POCO,但对于某些类型的应用程序,您不需要执行 DDD(如果您正在执行基于小数据的应用程序),因此关注点并不相同.

I use POCO when I'm doing DDD for example, but for some kind of application you don't need to do DDD (if you're doing small data based applications) so the concerns are not the same.

希望能帮到你

这篇关于Poco 与 ORM 的“大"优势是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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