Skip to main content

POCO

An Example POCO

Below is an example Plain Old C# Object for a Product.

public class Product
{
public Product(int id)
{
Id = id;
}

private Product()
{
// required for EF
}

public int Id { get; private set; }
// other properties and methods
}

This Product class is a POCO because it has no dependencies on third-party frameworks for behavior, especially persistence behavior. It doesn't require a base class, especially a base class in another library. It doesn't have any tight coupling to static helpers. It can be instantiated anywhere without difficulty. It is much more persistence ignorant than the previous example, but it's not entirely ignorant of persistence, since it has an otherwise useless private constructor declaration. As you can see from the comment, that private parameterless constructor is only there because Entity Framework needs it to instantiate the class when it is reading it from persistence.