Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the proxy meaning in EntityFramework?

Tags:

I've used EntityFramework as an ORM in my projects and I don't have any problem in using this technology. I heard EntityFramework creates a proxy. I want to know WHAT proxy this ORM creates? What it does? And, when EF creates it? In the other words, what is the meaning of term "proxy" frequently being used in ORM topics.

like image 749
saber Avatar asked Aug 25 '11 11:08

saber


People also ask

How can we disable proxy object creation in POCO?

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.

How many types of EF are there?

There are three approaches to model your entities in Entity Framework: Code First, Model First, and Database First. This article discusses all these three approaches and their pros and cons.

What is ProxyCreationEnabled?

ProxyCreationEnabled is set to true , child objects will be loaded automatically, and DbContext. Configuration. LazyLoadingEnabled value will control when child objects are loaded.

What is POCO in EF?

POCO Entities (Plain Old CLR Object) A POCO entity is a class that doesn't depend on any framework-specific base class. It is like any other normal . NET CLR class, which is why it is called "Plain Old CLR Objects". POCO entities are supported in both EF 6 and EF Core.


2 Answers

A proxy in the ORM world is an automatically generated type that inherits from your domain object type. The proxy represents an instance which has not been populated with data from the database yet, but only knows its own ID. Whenever a property which is mapped to the database is accessed, the proxy subclass will carry out the load from the database, so that the load is transparent to the client code.

Proxies are typically created when you have a relationship property between two entities which is lazily loaded. E.g. when you access the user.Address property, what is really returned is an Address proxy object. Only once you access a property of that object (e.g. user.Address.StreetName) the Address object proper will be loaded.

like image 76
Jonas Høgh Avatar answered Oct 27 '22 11:10

Jonas Høgh


See Working with Proxy Classes in this tutorial: http://www.asp.net/entity-framework/tutorials/advanced-entity-framework-scenarios-for-an-mvc-web-application

like image 32
tdykstra Avatar answered Oct 27 '22 13:10

tdykstra