There are two types of Entities in Entity Framework: POCO Entities and Dynamic Proxy Entities.
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.
These POCO entities (also known as persistence-ignorant objects) support most of the same query, insert, update, and delete behaviors as entity types that are generated by the Entity Data Model. The following is an example of Student POCO entity.
publicclassStudent
{
publicint StudentID { get; set; }
publicstring StudentName { get; set; }
publicDateTime? DateOfBirth { get; set; }
publicbyte[] Photo { get; set; }
publicdecimal Height { get; set; }
publicfloat Weight { get; set; }
publicStudentAddress StudentAddress { get; set; }
publicGrade Grade { get; set; }
}
Dynamic Proxy Entities (POCO Proxy)
Dynamic Proxy is a runtime proxy class which wraps POCO entity. Dynamic proxy entities allow lazy loading.
Note: Dynamic proxy entities are only supported in EF 6. EF Core 2.0 does not support them yet.
A POCO entity should meet the following requirements to become a POCO proxy:
A POCO class must be declared with public access.
A POCO class must not be sealed (NotInheritable in Visual Basic).
A POCO class must not be abstract (MustInherit in Visual Basic).
Each navigation property must be declared as public, virtual.
Each collection property must be ICollection<T>.
The ProxyCreationEnabled option must NOT be false (default is true) in context class.
The following POCO entity meets all of the above requirements to become a dynamic proxy entity at runtime.
Note: By default, dynamic proxy is enabled for every entity. However, you can disable dynamic proxy by setting context.Configuration.ProxyCreationEnabled = false; in the context class.
At runtime, EF API will create an instance of dynamic proxy for the above Student entity. The type of dynamic proxy for Student will be System.Data.Entity.DynamicProxies.Student, as shown below:
Use ObjectContext.GetObjectType() to find the underlying wrapped type by the dynamic proxy as shown below:
Want to print your doc? This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (