What is the proxy creation in the entity framework?

4

What is the purpose of disabling this feature?

    
asked by anonymous 02.01.2018 / 12:01

2 answers

4

Proxies are required for two features:

  • lazy load - navigation properties are loaded once you have accessed the first time
  • Tracking Dynamic Changes - If you modify any property in the entity, the context is notified of this change and you define the state of the entity. If dynamic change tracking is not used, the context should use snapshot change tracking, which means that all changes before saving occur by exploring all properties, even if they have not been changed.

Both techniques have other requirements:

  • lazy load - all navigation properties in the entity must be virtual. Lazy loading should be enabled.
  • Dynamic Tracking Changes - All mapped properties must be virtual.

link

    
02.01.2018 / 12:08
1

At first I see no purpose (benefit), unless you want to work in an environment that does not need a trace or that you want to do it manually.

A point that could be useful would be a case that you just need to read the data, in that case making the trace would not make sense it would serve more time to persist the information, so you could be using EF to read the information and use the Dapper to persist for example, or a read in a Read Only database. In these senario you would have a better performa-se.

It is necessary to understand that the proxy represents an instance that has not yet been populated with data from the database, but only knows its own ID. Whenever a property that is mapped to the database is accessed, the proxy subclass will load the database so that the load is transparent to the client code.

    
02.01.2018 / 12:23