[英]NHibernate & WCF in version 3.0
I've just started a new project which requires a WCF service to handle a distributed environment. 我刚刚开始了一个新项目,该项目需要WCF服务来处理分布式环境。 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. 我想使用NHibernate,但是我已经看到了几种解决序列化的方法。 Is this handled in 3.0?
这是在3.0中处理的吗? I noticed wcf_context inside the truck :D
我注意到卡车里面的wcf_context:D
If it isn't handled could someone point me in the right direction? 如果不处理,有人可以指出我正确的方向吗?
Thanks everyone 感谢大家
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. 通常,如果要从服务返回数据,则需要返回特定于该服务目的的类,其中包含与该服务调用有关的类,DTO(数据传输对象)或WCF中的DataContract世界。
One tool that is particularly helpful for mapping between entities and DTO's is AutoMapper . AutoMapper是对实体与DTO之间的映射特别有用的一种工具。 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.
无论您使用AutoMapper还是仅使用“左右”编码,这都可以防止延迟加载/延迟执行问题,因为执行映射将导致执行。
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) 从服务中返回实体可能不是一个好主意,原因有很多,以下是一些原因(大多数情况存在不同的看法)
You can't pass Lazy loaded object using WCF. 您不能使用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) 有一些解决方法,但是有一个错误会在下一WCF版本中修复(即将在2010年4月发布)
Other than that, they leave happily together, as long as you define the objects with the rigth DataContract. 除此之外,只要您使用严格的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) - 列表的序列化还有一个问题-您需要使用带有特定标志的svcutil生成代理,否则会发生不好的事情(列表变成数组,并且您无法添加更多项)(除非您使用某种类型的列表WCF和NHibernate都同意)-查找(Nhiberate和WCF列表)-
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.