Can you give a simple definition of NHibernate ‘proxy’ please.
As an example, this is a citation from Manning Nhibernate in Action book:
‘For a or
association, lazy fetching is possible
only if the associated class mapping
enables proxying.’
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It means that it will create a class that inherits your original entity, and override the actual property that would represent the associated class.
By that, it can implement logic that would fetch the data from DB in order to achieve the laziness, instead of always having that data available.
For Collections though, this is implemented in NHibernate versions of ISet and IList etc. This is only relevant in many-to-one or one-to-one relations.
Example:
This is a very simplistic version of it, hopefully it will give you an insight on how it works. This of course can bring problems into your app because you won’t have an instance of your actual Entity-type, but the derived one. If you’ve decorated your classes with attributes and such, those might not be identified (depending on your code). also, type checking etc can break if you’re not careful.