Description:
Generally, the binding works properly. But if a persistent class inherits XPBaseObject or one of its descendants (XPCustomObject, XPLiteObject, XPObject), the user cannot clear the editor's value. The editor displays the validation error when accepting an empty value.
Binding to Nullable properties works correctly if a persistent class inherits PersistentBase.
Answer:
XPCollection and Base XPO Classes are designed to provide backward compatibility with legacy DataSet-based WinForms applications. These classes make the migration to XPO easy. WPF is a modern platform that does not use most of the functionality used in WinForms binding. Moreover, some features can cause unwanted side effects.
We suggest using DevExpress.Xpo.PersistentBase as the base class for your persistent classes in WPF applications. This solution is applicable even if you plan to share the business model library with applications based on the WinForms platform. This is because you actually do not need the compatibility with DataSet in applications created from scratch.
Q: What functionality I will loose if I change the base class to PersistentBase?
A: XPObject, XPCustomObject, and XPBaseObject are "thin" classes. Each of them implements only one specific feature and inherits the remaining functionality from the PersistentBase class. Features implemented in these classes can be enabled using attributes.
1. The automatically incremented OID property. Add a property of the Int32 type to your class and decorate it with the Key attribute.
2. Optimistic Locking. Decorate your class with the OptimisticLocking attribute.
3. Deferred Deletion (GC column). Decorate your class with the DeferredDeletion attribute.
4. The GetCollection
method. Change the collection property type to IList<T> and use the GetList
method to return a property value.
We suggest that you implement a custom base class in order not to repeat these steps in all persistent classes. Decorate your class with the NonPersistent attribute and use it as a base class for other classes.
C#[NonPersistent]
[DeferredDeletion]
[OptimisticLocking]
public class BaseObject :PersistentBase {
public BaseObject(Session session) : base(session) { }
[Key(true)]
[Persistent("OID")]
private int fOid;
[PersistentAlias("fOid")]
public int Oid {
get=> fOid;
}
}
Visual Basic<NonPersistent, DeferredDeletion, OptimisticLocking>
Public Class BaseObject
Inherits PersistentBase
Public Sub New(ByVal session As Session)
MyBase.New(session)
End Sub
<Key(True), Persistent("OID")>
Private fOid As Integer
<PersistentAlias("fOid")>
Public ReadOnly Property Oid() As Integer
Function(get) fOid
End Property
End Class