NHibernate 和 NHibernate WCF 3.0版本
我刚刚开始一个新项目,需要 WCF 服务来处理分布式环境。我仍在努力寻找实现事物的最佳方法。
我想使用 NHibernate,但我已经看到了几种不同的方法来解决序列化问题。 3.0有处理这个问题吗?我注意到卡车内的 wcf_context :D
如果没有处理,有人可以指出我正确的方向吗?
谢谢大家
I've just started a new project which requires a WCF service to handle a distributed environment. I'm still trying to find the best way to implement things.
I want to use NHibernate, but I've seen a few different ways to address the serialization. Is this handled in 3.0? I noticed wcf_context inside the truck :D
If it isn't handled could someone point me in the right direction?
Thanks everyone
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常,如果要从服务返回数据,则需要返回特定于服务目的的类,其中包含与该服务调用相关的内容、DTO(数据传输对象)或 WCF 中的 DataContract世界。
对于实体和 DTO 之间的映射特别有用的一种工具是 AutoMapper。无论您使用 AutoMapper 还是仅使用“左右”编码,这都将防止延迟加载/延迟执行问题,因为进行映射将导致执行发生。
从服务返回实体可能不是一个好主意的原因有很多,这里有一些(对其中大部分有不同的意见)
Typically if you're going to return data from a service, you'll want to return a class specific for the purpose of the service, containing what is pertinent to that service call, a DTO (Data transfer object) or DataContract in the WCF world.
One tool that is particularly helpful for mapping between entities and DTO's is AutoMapper. Whether you use AutoMapper or just "left-right" coding, this will prevent the lazy loading / delayed execution issue because doing the mapping will cause the execution to occur.
There are a number of reasons why it might not be a good idea to return an entity from a service, here are a few (there are varying opinions on most of this)
您无法使用 WCF 传递延迟加载的对象。
有一些方法可以解决这个问题,但是有一个错误将在下一个 WCF 版本(即将推出,2010 年 4 月)中修复。
除此之外,只要您使用正确的 DataContract 定义对象,它们就会愉快地一起离开。
列表的序列化还存在一个问题 - 您需要使用带有特定标志的 svcutil 生成代理,否则会发生不好的事情(列表变成数组,并且您无法添加更多项目)(除非您使用某种类型的列表) WCF 和 NHibernate 都同意) - 查找(Nhiberate 和 WCF 列表) -
You can't pass Lazy loaded object using WCF.
there are some ways around it, but there is a bug which will be fixed in the next WCF version (coming soon, apr 2010)
Other than that, they leave happily together, as long as you define the objects with the rigth DataContract.
There is also an issue in serialization of Lists - You need to generate the proxy using svcutil with a certain flag or bad things happens (the lists becomes arrays and you can't add more items) (unless you use a certain kind of list that both WCF and NHibernate agrees) - look that up (Nhiberate and WCF Lists) -