What is the Creation proxy for in the Entity framework?

Asked

Viewed 88 times

4

What is the purpose of disabling this feature?

2 answers

4


Proxies are required for two resources:

  • Lazy load - navigation properties are loaded once you first accessed
  • Tracking of dynamic changes - If you modify any property in the entity, the context is notified of that change and set the status of the entity. If dynamic change tracking is not used, context should use snapshot change tracking, which means that all changes before saving occur, exploiting all properties even if they have not been changed.

Both techniques have other requirements:

  • Lazy load - all browsing properties in the entity must be virtual. Lazy loading must be enabled.
  • Dynamic tracking of changes - all mapped properties must be virtual.

https://stackoverflow.com/questions/6198563/entity-framework-proxy-creation

  • Thanks for the explanation, I had read the link you passed but it was not clear

1

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

A point that could be useful would be a case that you need only read the data, in that senario do the tracking would not have sense it would serve more at the time of persisting the information, then you could be using EF to read the information and use Dapper to persist for example, or a read in a Read Only database. In those rooms you’d have a better idea.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.