nhibernate跨机延迟加载问题
我有一个客户端、一个服务器和一个数据库 db 使用流畅的 nhibernate 映射到服务器。 到目前为止,一切都很好 客户端通过wcf与服务器进行对话。 我想在客户端实现延迟加载。
有什么解决办法吗?
i got a client a server and a db
db mapped to server with fluent nhibernate.
so far so good
the client talks with the server with wcf.
i want to implement lazy loading on client side.
is there any solution out there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
WCF 的本质是在发送之前了解数据的形成,即数据已被检索并放入某种数据契约中。
也许您可以在初始服务调用中提供一个参数来指示是否应填充子属性,尽管您要填充多远总是很棘手。
The nature of WCF would be to learn towards your data being shaped prior to sending, ie., it's already been retreived and put into a datacontract of some sort.
Possibly you could provide a parameter on the inital service call to indicate whether child properties should be populated, although how far you go is always going to be tricky.
当我意识到这不可能发生时,我决定使用投影和结果转换器。
效果很好。
如果我需要加载一些延迟加载集合,我只需在服务器上迭代它并将其发送回客户端,
当我想更新部分选定的对象时,我必须从数据库中重新选择他并更新完整的数据实体。
但这是值得的
when i realized that it can't happen, i decided to work with the projection and the result transformer.
it works good.
if i need to load some lazy loading collection i just iterate it on server and send it back to client,
when i wanna update a partially selected object i have to reselect him from db and update the full data entity.
but it's worth it
抱歉,我很悲观,但让 NHibernate 通过 WCF 进行延迟加载是无法工作的。
I'm sorry to be pessimistic but making NHibernate work with lazy loading over WCF is NOT GOING TO WORK.
使用以下代码,WCF 可以使用延迟加载:
With the below code WCF can work with lazy loading:
AFAIK 没有解决方案,延迟加载与 nhibernate 的代理机制一起工作,这对于其实现来说是非常固有的。
有一个名为 Nhibernate.Remote 的项目,但该项目已被放弃。
nhibernate 可以通过 wcf 工作,但没有延迟加载。
AFAIK there is no solution for that, lazy loading works with nhibernate's proxy mechanism which is very intrinsic to its implementation.
there was one project called Nhibernate.Remote but this has been abandoned.
nhibernate would work over wcf, but without lazy loading.