EF POCO DTO WCF 适配器模式
因此,我开始考虑将 EF 与 POCO 结合使用,并通过线路将 DTO 传输到我的 WCF 客户端。
看起来使用 DTO 来代替将 POCO 发送给客户端是一个很好的架构设计。
所以我在阅读相关内容时,很多时候都提到使用适配器模式将 POCO 转换为 DTO。
我似乎找不到任何描述用于 POCO => 的适配器模式的文章DTO。
有人可以解释一下吗?
So I'm starting to look into using the EF with POCO and transfering DTO over the wire to client of my WCF.
Looks like it's a good architectural design to go with DTO instead of sending POCO over to the client.
So I was reading about it and a lot of time it mentionned using the Adapter pattern to convert the POCO to DTO.
I can't seem to find any article describing the Adapter patter used for POCO => DTO.
Can someone shed a bit of light concerning this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Adapter 是具有确切含义的 GoW 模式。您不需要专门的文章来阅读有关在 POCO 和 DTO 之上使用它的信息(它与任何其他类相同)。但我认为你实际上并不想要一个真正的适配器。您想要将 POCO 转换为 DTO 的东西,反之亦然。许多开发人员正在使用非常好的库,称为 AutoMapper。我通常不使用适配器或 AutoMapper。相反,我的 DTO 有名为
ToPoco
和FromPoco
的静态方法 - 它很愚蠢,它更书面,但每个人都理解它。Adapter is GoW pattern with exact meaning. You don't need special article to read about using it on top of POCO and DTOs (it is same like with any other classes). But I think you actually don't want a real adapter. You want something which will convert POCO to DTO and vice versa. Many developers are using very good library called AutoMapper. I usually don't use neither adapter or AutoMapper. Instead my DTO's have static methods called
ToPoco
andFromPoco
- it is stupid, it is more writting but everybody understand it.这篇帖子讨论了两者的纯粹性。
但就将它们从一种转换为另一种而言,我过去曾使用过扩展方法。
因此,在通过网络发送 POCO 之前,我有这样的东西。
它将其转换为 WCF 数据契约 obj,序列化并通过网络发送。
另一方面,我
将它转换回 POCO。
它不是最优雅的,但它确实有效。
This post talks about the purity of the two.
But as far as converting them from one to the other, I have used extension methods in the past.
So before the POCO is being sent over the wire, I have something like this.
which converts it into a WCF datacontract obj, serialized and sent across the wire.
On the other side I have
Which converts it back into POCO.
It's not the most elegant, but it works.