DevForce entities have an EntityAspect property through which entity-related services are provided. POCO objects by their nature do not have such a property, but there are still ways to obtain access to entity services.
There are two ways in which to obtain an EntityAspect for a POCO object:
Use the EntityAspect.Wrap static method to obtain an EntityAspect for the POCO object.
C# | var stateAspect = EntityAspect.Wrap(aState); |
VB | Dim stateAspect = EntityAspect.Wrap(aState) |
Having done that, you can then work with the object as an entity and query its EntityState. For example:
C# | stateAspect.AddToManager(); bool isAdded = stateAspect.EntityState.IsAdded(); |
VB | stateAspect.AddToManager() Dim isAdded As Boolean = stateAspect.EntityState.IsAdded() |
…and of course, use any of the other facilities of the EntityAspect.
The IHasPocoEntityAspect is a simple interface that contains a single property of type EntityAspect. To add this implementation to a POCO type simply implement the interface and add an EntityAspect property with a default getter and setter as shown below:
C# | public class State : IHasPocoEntityAspect { //…[snip] [IgnoreDataMember] public EntityAspect EntityAspect { get; set; } } |
VB | Public Class State _ Implements IHasPocoEntityAspect '…[snip] <IgnoreDataMember> _ Public Property EntityAspect() As EntityAspect End Class |
Once you have implemented this interface your POCO entity will have direct access to this EntityAspect property, and DevForce will insure that it is properly initialized and configured.
The downside to implementing this interface is that your class is no longer a "pure" POCO class, but the upside is that you'll be able to use your POCO objects as you would any other DevForce entity.
DevForce has to keep track of its own bookkeeping data about each POCO instance. By default, DevForce uses a hashtable to maintain this data, and therefore needs to perform a lookup operation anytime you need access to any EntityAspect services.
What the IHasPocoEntityAspect interface does is provide a place for DevForce to keep its own bookkeeping data about each POCO instance on the instance itself, hence no need for the hashtable or the lookup.