23

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.

2
  • 1
    EF doesn't always create proxies. You can turn that off, which you might want to do if you eager load, or if you serialize the entities (e.g. for use in WCF). Commented Aug 25, 2011 at 13:00
  • I accepted the provided by Jonas, But I want to hear more from all experts. Commented Aug 25, 2011 at 17:21

2 Answers 2

35

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.

Sign up to request clarification or add additional context in comments.

Comments

5

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

2 Comments

I know that often links are frowned upon in SO answers, but this is a very useful tutorial.
True, useful link. Here another one: learn.microsoft.com/pl-pl/ef/ef6/fundamentals/proxies

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.