We can stop creation of proxy in the context constructor by using
this.Configuration.ProxyCreationEnabled = false;
What are the advantages and disadvantages of creating proxies in EF 4.1 ?
Dynamic Proxy IT can also be said that it is a runtime proxy classes like a wrapper class of POCO entity. You can override some properties of the entity for performing actions automatically when the property is accessed. This mechanism is used to support lazy loading of relationships and automatic change tracking.
ContextOptions. ProxyCreationEnabled property is true by default. You need to explicitly set it to "false" in the default constructor of your context object in order to turn this feature off.
ProxyCreationEnabled is set to true , child objects will be loaded automatically, and DbContext. Configuration. LazyLoadingEnabled value will control when child objects are loaded.
Proxies are necessary for two features:
Both these techniques have other requirements:
virtual
. Lazy loading must be enabled.virtual
.In addition to Previous answer, Runtime use your POCO class using reflection and create a Dynamic Proxy class inheriting your POCO class. So it will add those functionalities + EntityObject functionalities in runtime that will help Dynamic proxies to enable Lazy Loading and Dynamic change Tracking.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With