Skip to main content
.NET Standard 2.0+

XafDataView Class

A lightweight read-only list of data records (a data view) retrieved from a database without loading complete business objects. Can be queried much more quickly than a real objects collection.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v23.1.dll

NuGet Package: DevExpress.ExpressApp


public abstract class XafDataView :
public abstract class XafDataView :


You can query data via the XafDataView. To create an instance of the XafDataView, use the IObjectSpace.CreateDataView method.

The data view column names and expressions used to compute column values are specified by the XafDataView.Expressions list. By default, this list is empty and you should populate it manually. Both simple properties and complex expressions can be passed via the expressions parameter. The valid separator is a semicolon (;).

XafDataView dataView = (XafDataView)objectSpace.CreateDataView(
    typeof(Product), "ID;Name;Sales.Sum([Count] * Price)", null, null);

Alternatively, you can pass the IList<DataViewExpression> list via the expressions parameter. The data can be filtered and sorted with the criteria and sorting parameters.

List<DataViewExpression> dataViewExpressions = new List<DataViewExpression>();
    new DataViewExpression("ID", new OperandProperty("ID")));
dataViewExpressions.Add(new DataViewExpression(
    "Name.UpperCase", new FunctionOperator(FunctionOperatorType.Upper, new OperandProperty("Name"))));
dataViewExpressions.Add(new DataViewExpression(
    "Count", new AggregateOperand("Sales", Aggregate.Count)));
CriteriaOperator criteria = new BinaryOperator(
    "Sales.Count", 0, BinaryOperatorType.Greater);
SortProperty[] sorting = new SortProperty[] { 
    new SortProperty("Name", SortingDirection.Ascending)
EFCoreDataView dataView = new EFCoreDataView(objectSpace, typeof(Sale), dataViewExpressions, criteria, sorting);

When you access a particular data record by its index (see XafDataView.Item), an XafDataViewRecord object is returned.

XafDataViewRecord dataRecord = dataView[0];

To get a column value within a particular data record, use the XafDataViewRecord.Item property as follows:

int id = dataView[0]["ID"];

Here, the “ID” string is the name of the column within the XafDataView.Expressions list. If you use a semicolon-separated string to specify the columns set in the XafDataView constructor, the column name coincides with the expression text:

int total = dataView[0]["Sales.Sum(Count * Price)"];

Data records are not retrieved from the database when the XafDataView object is created. Instead, the database is queried when you access a specific record by its index or call one of the following methods for the first time:

Later, the cached data records are used by these methods. To refresh data, use the XafDataView.Reload method, which clears the cache.

You can limit the number of retrieved data records by using the XafDataView.TopReturnedObjectsCount property.

An XafDataView implements the IBindingList and ITypedList interfaces, so it can serve as a data source for a visual data-aware control.

The XafDataView class has two ORM-specific descendants. Depending on the current Object Space type, the IObjectSpace.CreateDataView method returns either DevExpress.ExpressApp.EFCore.EFCoreDataView (for Entity Framework Core) or XpoDataView (for XPO) object.


See Also