xpo-2056-examples-how-to-make-a-class-or-property-non-persistent.md
If you don’t want to store a property or a field that is persistent by default, you can explicitly mark it as non-persistent with the NonPersistentAttribute as shown in the following code example.
[NonPersistent]
public string NonPersistentField;
<NonPersistent()> _
Public NonPersistentField As String
You can also make the entire class non-persistent. One common example is when you want to have your own base class (say, MyBusinessObject) for all persistent objects. By default, XPO will create a table MyBusinessObject where it will store a record for every business object in the system. To avoid this, mark MyBusinessObject as non-persistent as shown in the following code snippet.
[NonPersistent]
public class MyBusinessObject: XPObject {
}
public class Contact : MyBusinessObject {
}
<NonPersistent()> _
Public Class MyBusinessObject : Inherits XPObject
End Class
Public Class Contact : Inherits MyBusinessObject
End Class
Note
XPO cannot restore non-persistent class references even if the actual object instance referenced is persistent. In the example above, XPO will not be able to restore reference to MyBusinessObject.
See Also