REST, Json and NHibernate lazy loading

2019-09-14 18:12发布

问题:

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.

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?

回答1:

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

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.



标签: c# json rest