NHibernate.IFutureValue>>序列化时包含 .Value

发布于 2024-10-22 19:52:23 字数 909 浏览 6 评论 0原文

我正在使用 NHibernate 构建一个 ASP.NET(2.0,不,我无法更改它)站点,并且有一个自定义 JSON 转换器,因此我无法序列化我想要对客户端隐藏的属性。这让我只需返回对象,而不必担心它们的序列化值 - 它们始终是安全的。

不幸的是,如果我使用 query.FutureValue(),被序列化的对象首先是 NHibernate.Impl.FutureValue 而不是我的实体,这意味着如果我将它放入字典中并将其返回给客户端,我会得到如下所示的 JSON:

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

以前我发现我无法让任何接口在 ASP 的 JavaScriptConverter 实现中工作...只有常规或抽象类。因此,返回 typeof(IFutureValue) 作为受支持的类型意味着我的转换器被完全忽略。我可以捕获 MyBaseClass,因为我之前重构了一些东西,使用抽象基而不是接口,但不是接口。

然后我发现 .Impl 中的 FutureValue 实现是程序集内部的,或者其他类似的废话,只会让我的 .NET 体验更加痛苦。所以我不能使用 typeof(FutureValue) 来处理这一切,因为 FutureValue 仅存在于我的调试会话中。

有没有办法从程序集中获取类类型?或者让 ASP 相信接口确实有用途的方法?或者可能有一些我可以访问的超类可以让我解决整个问题?

帮助!我喜欢我的 Futures,它可以让我一次批量处理大量呼叫!

(如果有不清楚的地方,或者您想要更多代码,请务必询问!我可以发布很多内容。)

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. 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:

{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. So returning typeof(IFutureValue<MyBaseClass>) as a supported type means my converter is completely ignored. I can catch MyBaseClass, because I refactored things earlier to use an abstract base instead of an interface, but not the interface.

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. So I can't use typeof(FutureValue<MyBaseClass>) to handle it all, because FutureValue exists only in my debugging sessions.

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? 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.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

转瞬即逝 2024-10-29 19:52:23

如果我理解正确的话,你似乎把事情混在一起了。

听起来您正在尝试序列化 query.FutureValue() 的实例,这毫不奇怪地为您提供了:一个 JSON 对象,其中 Value 字段具有代表您的实体的 JSON。

对我来说,听起来您真的只想序列化query.FutureValue().Value

像这样使用 NHibernate future 给你带来的好处很少,所以你可能会想:

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);

这有意义吗?

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.

To me it sounds like you really want to just serialize query.FutureValue<class>().Value.

Using NHibernate futures like this gives you little benefit though, so you're probably after something like:

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文