简体   繁体   English

NHibernate.IFutureValue <>进行序列化时包括.Value

[英]NHibernate.IFutureValue<> when serialized includes .Value

I'm building an ASP.NET (2.0, no, I can't change it) site with NHibernate, and have a custom JSON converter so I can not-serialize properties I want hidden from the client. 我正在使用NHibernate构建一个ASP.NET(2.0,不,我不能更改它)站点,并且具有自定义JSON转换器,因此我无法序列化要从客户端隐藏的属性。 This lets me just return the objects, and never have to worry about their serialized values - they're always secure. 这让我只返回对象,而不必担心它们的序列化值-它们始终是安全的。

Unfortunately, it appears that if I use query.FutureValue<class>() , the object that gets serialized is first the NHibernate.Impl.FutureValue<class> and not my entity, which means I get JSON that looks like this if I throw it in a dictionary and return it to the client: 不幸的是,似乎如果我使用query.FutureValue<class>()query.FutureValue<class>()序列化的对象首先是NHibernate.Impl.FutureValue<class>而不是我的实体,这意味着如果我抛出,我将得到如下所示的JSON在字典中将其返回给客户端:

{key: { Value: { /* my serialized object properties */ } }

Previously I discovered that I can't get any interfaces to work in ASP's JavaScriptConverter implementations... only regular or abstract classes. 以前,我发现我无法在ASP的JavaScriptConverter实现中使用任何接口,而只能使用常规或抽象类。 So returning typeof(IFutureValue<MyBaseClass>) as a supported type means my converter is completely ignored. 因此,返回typeof(IFutureValue<MyBaseClass>)作为受支持的类型意味着我的转换器被完全忽略了。 I can catch MyBaseClass, because I refactored things earlier to use an abstract base instead of an interface, but not the interface. 我可以了解MyBaseClass,因为我之前已经重构了东西,以使用抽象库而不是接口,而不是接口。

And then I discover that the FutureValue implementation in .Impl is internal to the assembly, or some other such nonsense that only serves to make my .NET experience even more painful. 然后,我发现.Impl中的FutureValue实现是程序集的内部内容,或者是其他一些废话,这些内容只会使我的.NET体验更加痛苦。 So I can't use typeof(FutureValue<MyBaseClass>) to handle it all, because FutureValue exists only in my debugging sessions. 因此,我无法使用typeof(FutureValue<MyBaseClass>)来处理所有问题,因为FutureValue仅存在于我的调试会话中。

Is there a way to get the class type out of the assembly? 有没有办法从程序集中删除类类型? Or a way to convince ASP that interfaces do in fact have uses? 还是一种使ASP确信接口确实有用途的方法? Or might there be some superclass I can access that would let me get around the whole issue? 还是可能有一些我可以访问的超类可以解决整个问题?

Help! 救命! I like my Futures, it lets me batch a whole heck-ton of calls at once! 我喜欢我的期货,它使我可以立即批量处理大量的电话!

(if something isn't clear, or you want more code, by all means, ask! I can post quite a bit.) (如果不清楚,或者您想获取更多代码,请询问!我可以发表很多内容。)

If I'm understanding you correctly, it seems you are mixing things a together a little bit. 如果我对您的理解正确,似乎您正在将某些事情混在一起。

It sounds like you're trying to serialize an instance of query.FutureValue<class>() , which unsurprisingly gives you just that: a JSON object where the Value fields has JSON representing your entity. 听起来您正在尝试序列化query.FutureValue<class>()的实例,这毫不奇怪地为您提供了一个:JSON对象,其中Value字段具有表示您的实体的JSON。

To me it sounds like you really want to just serialize query.FutureValue<class>().Value . 对我来说,听起来您真的只想序列化query.FutureValue<class>().Value

Using NHibernate futures like this gives you little benefit though, so you're probably after something like: 像这样使用NHibernate期货并没有给您带来什么好处,因此您可能会追求以下目标:

var future1 = query1.FutureValue<SomeEntity>();
var future2 = query2.FutureValue<AnotherEntity>();

var json1 = serializer.Serialize(future1.Value); //<BAM! Multi-query gets fired!
var json2 = serializer.Serialize(future2.Value);

Does that make sense? 那有意义吗?

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

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