POCO Class

Topic updated 25-4-2007

Every Table Template in a BO-Layer project generates one POCO Class. POCO Class instances are used by applications for in-memory storage of the information of single rows from database Tables, Views and Custom Views as defined in the Database Repository.

The POCO Class does not implement any data access code. This is handled by the Factory Class.

POCO (Plain Old C# Object) is derived from POJO (Plan Old Java Object), a term coined in the Hibernate community. It means that the basic classes used  to map database entities are free from requirements such as code attributes, derivation from base classes, implementation of interfaces, etc. Such requirements have been typical of other ORM (Object Relational Mapping) solutions. Use of POCO/POJO classes is a typical trait of the Hibernate and NHibernate frameworks, where all mapping information is stored in separate xml files.

 

Relations and collections

Relations to other database entities as defined in the Database Repository are translated to object properties and strongly typed collection properties on POCO Classes:

If an entity has a one-to-many relation to another entity, its POCO Class will have a property of the Collection Class type of the related entity, to reference all child objects.
If an entity has a many-to-one relation to another entity, its POCO Class will have a single object property to reference its parent object.

 

If a POCO Class has one or more collections, it will have an Add() and Delete() method for each collection. This allows the manipulation of collections of related objects straight from the POCO Class instance.

Manipulation of collections does not directly lead to database updates, these will only occur if a Factory Class instance is called to perform the right CRUD operations.

 

POCO Class enhancement

POCO Classes can be enhanced in the following ways:

By adding custom code
By setting a base class (POCO Base Class option of the Table Template)