Skip to main content
.NET 6.0+

PersistentCriteriaEvaluationBehavior Enum

Lists values that specify how filter criteria are evaluated within a transaction.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v24.1.dll

NuGet Package: DevExpress.Xpo

Declaration

public enum PersistentCriteriaEvaluationBehavior

Members

Name Description
BeforeTransaction

Criteria are evaluated on the data store side. Objects created within a transaction (Cache), are not processed by the criteria. Objects modified within a transaction, are not processed. Instead, their images, stored in the data store, are processed by the criteria.

InTransaction

All objects (Data Store and Cache) are processed by the filter criteria.

Remarks

Values listed by this enumeration specify which objects are processed when a criteria is being evaluated.

Example

Creating a new XPCollection with the criteriaEvaluationBehavior parameter set to BeforeTransaction doesn’t add objects that have been created or changed within a transaction.

// Creates a new persistent object and saves it to a data store.
MyObject obj1 = new MyObject(session1);
obj1.Name = "Mike";
obj1.Save();
// Creates a new XPCollection.
XPCollection<MyObject> xpCollection = new XPCollection<MyObject>(unitOfWork1);
// Gets the number of objects within the collection.
// count = 1
int count = xpCollection.Count;
// Begins a transaction.
using (UnitOfWork uw = session1.BeginNestedUnitOfWork()) {
    // Creates a new object within the transaction.
    MyObject obj = new MyObject(uw);
    obj.Name = "John";
    // Creates a new collection and populates it.
    XPCollection<MyObject> collection =
    new XPCollection<MyObject>(PersistentCriteriaEvaluationBehavior.BeforeTransaction, uw, null);
    // Gets the number of objects within the collection.
    // count2 = 1
    int count2 = collection.Count;
    uw.CommitChanges();
    // count2 = 1
    count2 = collection.Count;
}

To allow these objects to be added to the collection, the criteriaEvaluationBehavior parameter must be set to InTransaction. Note, this significantly slows down the application’s performance.

MyObject obj1 = new MyObject(session1);
obj1.Name = "Mike";
obj1.Save();
XPCollection<MyObject> xpCollection = new XPCollection<MyObject>(unitOfWork1);
// Gets the number of objects within the collection.
// count = 1
int count = xpCollection.Count;
using (UnitOfWork uw = session1.BeginNestedUnitOfWork()) {
    MyObject obj = new MyObject(uw);
    obj.Name = "John";
    XPCollection<MyObject> collection =
       new XPCollection<MyObject>(PersistentCriteriaEvaluationBehavior.InTransaction, uw, null);
    // Gets the number of objects within the collection.
    // count2 = 2
    int count2 = collection.Count;
    uw.CommitChanges();
    // count2 = 2
    count2 = collection.Count;
}
See Also