What is the Dynamic Proxy generated by the Entity Framework?

Asked

Viewed 818 times

4

What is the Dynamic Proxy generated by the Entity Framework? And a class? What is its function?

1 answer

9


The Dynamic proxy works similar to the nhibernate proxy, it is an entity proxy (POCO class). It is a class that overrides the entity’s virtual properties to be able to load. Which comes down to loading the data only at the time they are requested.

The Lazy load is widely used in lists of objects (e.g. an employee’s dependent list) but can be used in common properties (e.g. in general. String property that has very long text).

Take a look at this documentation about Lazy Load, which is the on-demand load and Eager Load which is a technique that eliminates a problem called n+1, where the ORM calls the BD to search for 1 parent record and N child records. With Eager load you search everything in one call.

Replying to your comment:

Proxy is a project standard (http://www.dofactory.com/net/proxy-design-pattern) which creates a substitute class simulating the original class. Orms create a substitute class to do Lazy Load as follows: They create a proxy class with only the ID filled and pass as if it were the full class and keep monitoring the proxy properties. When we try to access a property that was not loaded (e.g. Name) the ORM goes to the database and looks for the correct value. This is Lazy load. And you are correct EF also uses proxy to monitor changes (change tracking)

  • What is a proxy? Basically it generates a class from the superscript of the properties declared as virtual for use of Lazy load? Just this? If I’m not mistaken (and I may be mistaken, I’m very confused) I read in some corner that he also had part in the change tracking...

  • @Caiquec. I tried to answer your questions simply by changing the answer. If it was not very clear let me know. Sds.

Browser other questions tagged

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