A POCO class is a .NET class that has no dependencies on DevForce. In order for DevForce to be able to query and save instances of such types there are a few simple implementation details to consider.
Let's start with a simple example. Below is a "State" class representing US states, with only two properties:
C# | using System; using System.ComponentModel.DataAnnotations; namespace DomainModel { public class State { [Key] public string Abbrev { get; set; } public string Name { get; set; } } } |
VB | Imports System Imports System.ComponentModel.DataAnnotations Namespace DomainModel Public Class State <Key()> Public Property Abbrev() As String Public Property Name() As String End Class End Namespace |
You'll notice we added the Key attribute. This is optional, but indication of the primary key for an entity allows DevForce to cache instances of it, since each State object will have unique "identity" and can be easily differentiated from others. Since these objects are now cacheable, they can also be created, modified or deleted, and saved.
In the simple case here with the State class, since the US is unlikely to see any changes in its states, your application will therefore probably not be doing any additions, modifications or deletions, and you can omit the Key attribute. You would still be able to query for these objects, but the EntityManager would not add them to its cache, and you cannot execute CacheOnly queries for these objects.
We're not done yet, though, since you'll still have to tell DevForce how to query, and optionally save, your POCO objects, which we'll cover in a later topic. For now, we'll delve into some additional considerations.
It's important to note that if objects of a POCO class will only be queried and your application is not an n-tier or Silverlight application, then you probably don't need to do anything additional.
The following rules apply to serialization. DevForce will serialize entities in a distributed application, when working with an EntityCacheState, and when saving entities.
We saw above that the Key attribute is used to uniquely identify POCO objects, but it serves a double purpose: when DevForce sees this attribute it will automatically include the type in its known type processing.