将 Castle ActiveRecord/NHibernate 与 WCF 结合使用时是否存在任何问题?
Activerecord 为我们的数据库设计提供了灵活性,我们正在为 DAL 考虑它并围绕它构建模型。 我们将在此之上创建一个 WCF 服务。 使用基于 NHibernate 的 Castle Activerecord 时是否存在任何问题或兼容性问题? 特别是当涉及到 WCF 使用的 DataContractSerializer 时。 既然 ActiveRecord 不会使用 IQueryable,是不是太值得错过了?
The kind of flexibility that Activerecord gives to our DB design, we are looking at it for our DAL and build model around it. We will be creating a WCF service on top of all this. Are there any gotchas or compat issues when using NHibernate based Castle Activerecord? Specially when it comes to the DataContractSerializer that WCF uses. Since ActiveRecord will not be using IQueryable, is it too much to miss??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
序列化对象=分离对象。 一旦您通过 WCF 通过网络发送了一个对象,您就得到了这个对象。
因此,最大的问题是,当将 NHibernate 与 WCF 一起使用时,您将要处理的是分离对象,这迫使您以稍微不同的方式编写代码。 您将失去 NHibernate 的缓存功能和延迟加载功能。 在通过网络发送聚合之前,您必须预先加载它们。
当然,如果您使用数据传输对象,那么这一切都毫无意义,但既然您提到了 ActiveRecord,我猜这不是计划。
我可能在这里偏离了基地。 希望ActiveRecord高手能够提供更多细节。
Serialized object = detached object. And once you send an object over the wire via WCF, that's what you've got.
So the big issue is that you're going to be dealing with when using NHibernate with WCF is detached objects, which forces you to write your code a bit differently. You lose NHibernate's caching abilities and lazy loading features. You've got to pre-load your aggregates before you ship them off over the wire.
Of course that's all moot if you utilize data transfer objects instead, but since you mentioned ActiveRecord I am guessing that wasn't the plan.
I may be way off base here. Hopefully an ActiveRecord guru can give more details.
虽然不是特定于 WCF 和 Castle Activerecord,但我确实提供了一个警告。
确保您没有在持久层定义任何级联删除。 让 ActiveRecord 为您处理这些问题,否则您稍后会遇到烦人的错误(收到 0 预期 1)键入不太清楚的内容。
另外,如果您需要频繁进行批量删除,您可能需要小心使用 ActiveRecord,因为 Castle 实现不支持批量删除,而是需要对每个要删除的项目进行昂贵的循环并进行单独的删除。
While not specific to WCF and Castle Activerecord I do offer a warning.
Make sure you don't have any CASCADING DELETEs defined at the persistance layer. Let ActiveRecord handle those for you else you will encounter annoying errors later one (recieved 0 expected 1) type things that aren't very clear.
Also, if you need to do frequent bulk deletion you may want to be careful using ActiveRecord at all as the Castle Implementation doesn't support a bulk delete but instead requires a costly loop over each item to be deleted and individual deletes to occur.