ProgrammerGuide.Net | Step by Step Programmer Guide



POCO stands for Plain Old CLR Objects. It is just like any other normal or plain .NET CLR class which is why it is named so. A POCO entity is a class that doesn’t depend on any framework-specific base class. The POCO entities are also known as persistence-ignored objects and are supported in both EF 6 and EF core.

On the other hand, DTO which stands for Data Transfer Objects are used by developers to pass the data between layers. POCOs are also used for the same work but since they also become heavy, DTOs are preferred over POCOs in this case.

Difference between POCO and DTO:

The main difference between them is that DTO only contains public members and not any other methods hereby making it easier for sending the data as DTOs are also lightweight.

Let us have a look at the given below code:

public class Customer
public virtual int CustomerID {get; set }
public virtual string Name
public virtual string Address
//Defines a navigation property as a collection of SalesOrder objects.
public virtual ICollection<SalesOrder> SalesOrders { get; set }

This code defines a POCO class.

Steps to create POCO classes:

  1. • First, we need to disable the “auto create classes” or “auto-create code generation” as this generates context classes entity mode in Model1.designer.cs. To remove it, right-click on model1.edmx -> select properties.
  2. • Remove the value of Custom Tool as EntityModelCodeGenerator. After removal we won’t see Model1.designer class in modal1.edmx.
  3. • Double-click on Modal1.edmx and then right click on the designer surface -> code generation items. A window will open from where select ADO.NET POCO Entity Generator -> Add. Please Note: If you’re unable to see ADO.NET POCO Entity generator then you must install NuGet Package Library.
  4. • Two classes will be shown namely – and
  5. • – It is a context file and can be modified if you want to generate your template. Model1.context.cs file has a context class.
  6. • – It is an entity file and .cs files under are the entity classes.

These entities fulfil all the requirements of POCO proxy entities. Entity classes can be used as POCO entities or POCO Proxy entities as by default it behaves as POCO Proxy entities. But, in order to remove the default setting, you can disable proxy creation by setting a property “ObjectContext.ContextOptions.ProxyCreationEnabled = false”

Please click here for related products on Amazon!


Add comment

Want to Check Celebrities News?