Reputation: 975
As you know when we are using lazy mode to retrieve data in NHibernate
, A Proxy object creates instead the real object to keep connection track if we need to load rest of data and etc, But when you want to serialize the object to send it via Web Api
(Just for example) you will got an error that says you there is a proxy object and it can not be serialized, There is a lot of methods to make silence this proxy
- NhibernateUtil library
- 3rdParty Library
- Write a code to find proxy object on serialization progress and make the proxy properties off
I'm looking for the best pattern to do that, Is there any one that done it as well and ready to share it with us?
Upvotes: 0
Views: 150
Reputation: 16409
Converting NHibernate Entity (proxy) objects to DTO looks better approach to me. Refer this question.
Doing so, you are free to use DTO the way you want. There are multiple problems while using NHibernate Entity object as is everywhere.
These could be overcome by converting Entities to DTOs.
Please note that there are some other problems with this approach as well those I have mentioned in question.
Upvotes: 3