开发者

Entity Framework Proxy creation

开发者 https://www.devze.com 2023-03-09 13:27 出处:网络
We can stop creation of proxy in the context constructor by using this.Configuration.ProxyCreationEnabled = false;

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 ?


Proxies are necessary for two features:

  • Lazy loading - navigation properties are loaded once accessed first time
  • Dynamic change tracking - if you modify any property in the entity the context is notified about this change and set the state of the entity. If dynamic change tracking is not used, context must use snapshot change tracking which means discovery all changes before saving takes place = exploring all properties even if they were not changed.

Both these techniques have other requirements:

  • Lazy loading - all navigation properties in the entity must be virtual. Lazy loading must be enabled.
  • Dynamic change tracking - all mapped properties must be 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号