0

Is it a good idea to return nHibernate Entity from WebApi? For simple entity I tried to use this but what about complex entities. How will lazy loading be handled in that case?

1
  • 1
    Well, I do use NHiberante, web-api and angularjs. And what does go form DB to UI and back is POCO object. But it is not for free. You have to manage serialization. So either you will use custom JSON Resolvers (injectable into web api) or convert POCO into DTO decorated with [Json] attributes. But in general, it is feasable... Maybe start, try to play with, google and ask here once an issue will appear... Commented Jun 17, 2014 at 10:53

1 Answer 1

4

It is possible to return complex entities via WebAPI, however it is not the best way to do it, what I would suggest is create a DTO object to match the client side operation map it to the NHibernate entity and send it over the API.

With regard to the lazy loading, it will have no use if you expose the object via the web API, as the object serializes all the properties of the entity will be accessed and they will be loaded from the persistence, so in fact using lazy loading is inefficient in this scenario.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.