忽略NHibernate代理的公共/内部字段 [英] Ignore public/internal fields for NHibernate proxy

查看:200
本文介绍了忽略NHibernate代理的公共/内部字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些实体类型,我想懒加载。然而,他们有一些内部(组装)领域,他们揭露,但不在该类以外使用。这些字段是编译器生成的(F#),我不能改变它们。一个例子是:

lockquote
NHibernate.InvalidProxyTypeException:
以下类型不能用作
代理: Mappings.MTest:字段ID @ 47
不应该是公共的也不是内部的


我明白为什么NHibernate会这样做,如果有字段,如果我访问它们,将会扰乱生成的代理的延迟加载属性。但是,因为我知道我不会使用字段,我可以重写NHibernate吗?

有什么办法可以说忽略这个字段?我使用流利NHibernate,如果这使得它更容易。
$ b $编辑:我也应该注意到,我使用的是NHibernate 2.1.0 Alpha 2。



Edit2:这里的主要要点是我要保持启用LazyLoading,这意味着我必须使用代理生成。禁用LazyLoading工作(没有代理),但sorta击败了一个好的框架,如NHibernate的目的。

解决方案

我重新组装NHibernate比得到源和重建),并删除内部/公共领域的错误的代码。没有这个检查,LazyLoading看起来工作得很好。 (虽然,我是NHibernate的新手,所以有可能是我不知道的场景。)
$ b

编辑:
啊,有一个属性,use_proxy_validator,将禁用所有验证检查。

 流利的.Configure()
.ExposeConfiguration(fun cfg - >
cfg。 Properties.Add(use_proxy_validator,false))...


I have some entity types that I would like to lazy load. However, they have some internal (assembly) fields they expose, but are not used outside that class. These fields are compiler generated (F#) and I cannot change them. The an example exception is:

NHibernate.InvalidProxyTypeException: The following types may not be used as proxies: Mappings.MTest: field id@47 should not be public nor internal

I understand why NHibernate is doing this, and how having fields, if I accessed them, would mess up the lazy-loading properties of the proxies that are generated. However, since I know I won't be using the fields, can I override NHibernate somehow?

Is there any way I can say "ignore this field"? I'm using Fluent NHibernate, if that makes it easier.

Edit: I should also note, I'm using NHibernate 2.1.0 Alpha 2.

Edit2: The main gist here is that I want to keep LazyLoading enabled, which means I have to use the proxy generation. Disabling LazyLoading works (no proxies), but sorta defeats the purpose of a nice framework like NHibernate.

解决方案

I reassembled NHibernate (easier than getting the source and rebuilding) and removed the code that errors on internal/public fields. LazyLoading appears to work just fine without that check. (Although, I'm new to NHibernate and so there are probably scenarios I don't know about.)

Edit: Ah, there is a property, "use_proxy_validator" that will disable all validation checks. Good enough.

Fluently.Configure()
    .ExposeConfiguration(fun cfg -> 
        cfg.Properties.Add("use_proxy_validator", "false"))...

这篇关于忽略NHibernate代理的公共/内部字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆