REST、Json 和 NHibernate 延迟加载 [英] REST, Json and NHibernate lazy loading

查看:32
本文介绍了REST、Json 和 NHibernate 延迟加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何可取的方法来坚持从 REST api 延迟加载?使用 NHibernate 时,您可以选择延迟加载,这样如果您有一个包含地址"对象集合的Person"对象,那么在访问该集合之前不会从数据库加载该集合.

Is there any advisable way to persist lazy loading from a REST api? When using NHibernate you have the option of lazy loading so that if you have a "Person" object that contains a collection of "Address" objects then that collection wont be loaded from the database until the point of it being accessed.

但是,如果您返回一个表示 Person 的 Json 对象,是否有一种既定的方法来返回对 REST 资源的引用,以便在访问 Person.Addresses 时,它可以对适当的 URI 进行 REST 调用并返回适当的数据?

However if you return a Json object representing a Person is there an established way to return a reference to the REST resource so that when Person.Addresses is accessed that it makes the REST call to the appropriate URI and returns the appropriate data?

推荐答案

您正在寻找的概念是超媒体.所以你的人会有指向地址的链接.

The concept you are looking for is Hypermedia. So your Person would have links to Addresses.

这里有一个很好的视频来解释超媒体 API http://oredev.org/2010/sessions/hypermedia-apis

Here is a good video to explain Hypermedia APIs http://oredev.org/2010/sessions/hypermedia-apis

您必须选择支持此功能的媒体类型.

You'll have to pick a Media Type that supports this.

这篇关于REST、Json 和 NHibernate 延迟加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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