JSON.NET和nHibernate集合的延迟加载 [英] JSON.NET and nHibernate Lazy Loading of Collections
本文介绍了JSON.NET和nHibernate集合的延迟加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人将JSON.NET与nHibernate结合使用吗?我发现尝试加载带有子集合的类时遇到错误.
Is anybody using JSON.NET with nHibernate? I notice that I am getting errors when I try to load a class with child collections.
推荐答案
我也遇到了同样的问题,所以我尝试使用@Liedman的代码,但是从未调用过GetSerializableMembers()
作为代理引用.
我找到了另一种方法来覆盖:
I was facing the same problem so I tried to use @Liedman's code but the GetSerializableMembers()
was never get called for the proxied reference.
I found another method to override:
public class NHibernateContractResolver : DefaultContractResolver
{
protected override JsonContract CreateContract(Type objectType)
{
if (typeof(NHibernate.Proxy.INHibernateProxy).IsAssignableFrom(objectType))
return base.CreateContract(objectType.BaseType);
else
return base.CreateContract(objectType);
}
}
这篇关于JSON.NET和nHibernate集合的延迟加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文