2

我们正在开发一个应用程序,它应该使用实体框架及其简单的 WCf Soap 服务(不是 Wcf 数据服务)。我现在很困惑,我已经阅读了以下这些帖子,但我不明白该去哪里这个问题几乎相同,但我有使用 POCO 的限制并尽量避免 DTO。它不是那么大的服务。但是我提到的链接在回答它时写道,如果我尝试在线发送 POCO 类,序列化就会出现问题。

这篇文章已经实现了与我的问题相关的解决方案,但他没有提到任何与序列化问题相关的内容。他只是更改了我在许多其他文章中也发现的 ProxyCreationEnabled =false。

但是这些帖子也有点老了,所以今天的推荐是什么。我还必须发布并获取大量 Word/Excel/PDF/Text 文件,所以发送 POCO 类是否可以,否则序列化会出现问题。

谢谢!

4

1 回答 1

2

I definitely do not agree with this answer. The answer mentioned suggests to reinvent the wheel (The answer does not even indicate why not using POCOs).

You can definitely go with POCOs, I see no reason to have serialization issues; but if you have any, you can write DTOs for these specific problematic parts and map them to POCOs in the Business layer.

It is a good practice to use POCOs as the name itself suggests; Plain Old CLR objects. Writing the same classes again instead of generating them will not have any advantage. You can simply test it.

UPDATE:

Lazy Loading: Lazy loading means fetching related objects from database whenever they are accessed. If you have already serialized and deserialized an entity (ex. you have sent the entity to client side over a wire), Lazy Loading will not work, since you will not have a proxy in the client side.

Proxy: Proxy class simply enables to communicate with DB (a very simple definition by the way). It is not possible to use an instance of Proxy in the client side; it does not make sense. Just seperate the Proxy class and POCO entities into two different DLLs and share only the POCO objects with the client. And use the proxy in the service side.

于 2012-09-04T06:55:20.993 回答