简体   繁体   English

NHibernate部分从数据库加载实体,从WCF部分加载

[英]NHibernate part load entity from database, part load from WCF

I've been looking at loading enities from WCF: 我一直在考虑从WCF加载enities:

NHibernate: Lazy loading of IUserType NHibernate:延迟加载IUserType

NHibernate: Many-to-one IUserType NHibernate:多对一IUserType

Preloading IUserType with values from webservice 使用来自webservice的值预加载IUserType

I've worked out how to lazy load the entity from WCF: you have to create your own proxy which calls WCF and return it from IUserType, but I'll blog this at some point. 我已经研究了如何从WCF延迟加载实体:你必须创建自己的代理,调用WCF并从IUserType返回它,但我会在某个时候发布这个博客。

My question now is, can I part load an entity from the database in the usual way, so some properties are populated (ones that are stored locally) but for other properties, it has to call WCF? 我现在的问题是,我可以用通常的方式从数据库中加载一个实体,因此填充了一些属性(本地存储的属性)但是对于其他属性,它必须调用WCF吗? The local properties are ones that might be searched on, or returned in a query (Can't call WCF for each one - would be too slow), and the others would be called if the system needed to perform some business logic on it. 本地属性是可以搜索或在查询中返回的属性(不能为每个属性调用WCF - 会太慢),如果系统需要在其上执行某些业务逻辑,则会调用其他属性。

The problem is that I don't think I can use IUserType here, because I would need to use bag/set for my collections as I would want them to be eager loaded. 问题是我不认为我可以在这里使用IUserType,因为我需要为我的集合使用bag / set,因为我希望它们能够被加载。 Is there any way this can be done? 有什么办法可以做到吗?

Edit: 编辑:

It would be ideal if I could force NHibernate to return a proxy, and some how I could have access to the interceptor on that proxy, or even specify my own interceptor? 如果我可以强制NHibernate返回一个代理,以及一些我如何能够访问该代理上的拦截器,甚至指定我自己的拦截器,那将是理想的选择?

it is possible to inject your own custom interceptor. 可以注入自己的自定义拦截器。 You need to provide an interceptor for the session which instantiates the objects and sets your own LazyInitializer, see here under Proxy fac­tory 您需要提供哪些实例化对象,并设置自己的LazyInitializer会话拦截器,看到这里代理工厂

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM