我正在开发一个使用 NHibernate 进行数据库交互的模型。有一个名为 PostCategory 的类,其中包含延迟加载的 Post 集合,我正在使用 NewtonSoft.Json API 将对象序列化为 JSON。
当我尝试序列化 PostCategories 集合时,它们会抛出错误,因为其中包含延迟加载的帖子。目前,我正在创建一个匿名查询,以仅从 PostCategory 中选择特定属性,并将该查询序列化为 JSON。
有没有更好的解决方案来克服这个问题?
维贾亚·阿南德
I'm working on a model that uses NHibernate for database interaction. There is a class called PostCategory that contains a collection of Post that are lazy-loaded and i'm using NewtonSoft.Json API for serializing the objects into JSON.
When I try to serialize the collection of PostCategories they throw error beacause of the lazy-loaded posts inside them. Currently I've creating an anonymous query to select only the particular properties from the PostCategory and serializing that query into JSON.
Is there any better solution to overcome this problem?
Vijaya Anand
发布评论
评论(1)
我建议您按照 ayende 此处。
I would suggest you to serialize an anonymous object as explained by ayende here.