IPersistentObject and the ObjectHelper Class

The functionality that is added by the Enhancer during compilation is not available before compilation and enhancement. This functionality is encapsulated in the lPersistenctObject Interface. In order to have IntelliSense available, you can implement empty method and property bodies for your persistent classes. The enhancer will replace this bodies with new useful implementations. The New Class wizard of the NDO toolbar automatically generates such an empty implementation of IPersistentObject in a partial class. So, you dont't have to bother about IntelliSense.

If you do not want to work with the empty implementation, you can use the ObjectHelper class to access the IPersistentObject functions. Suppose, you want to work with the ObjectId of a persistent object in the code of the respective class:

[NDOPersistent]

public class Employee

{

    public void foo()

    {

        Console.WriteLine(this.NDOObjectId.ToString());

    }

}

The compiler would issue an error message, because the property NDOObjectId does not exist at compile time.

In this situation the static functions of the ObjectHelper class come into play. Instead of using a term of the pattern

Objectname.IPersistenceCapableMethod(<parameters>)

you can write

ObjectHelper.IPersistenceCapableMethod(<object name>, <parameters >)

The compiler can translate this call without the Enhancer functionality. Normally you just need the ObjectId property from the IPersistenceCapable interface. To obtain the ObjectId of an object you’d write:

ObjectId oid = ObjectHelper.GetObjectId(this);

For a list of all members of this type, see ObjectHelper Members.

Often a conversion is sufficient too:

ObjectId oid = ((IPersistenceCapable)this).NDOObjectId;