How This Works
In short, 'NO', it is not possible in a general case, and this permanent limitation is unrelated to DevExpress. Let's elaborate more:
- Database servers have no knowledge of values that exist only in memory on the client side (for instance, arbitrary C# or VB.NET logic in getters of calculated properties).
- Thus, database servers cannot physically execute sort, group and filter operations against such runtime values - SQL operates only against physical values stored in database tables and columns.
- In turn, DevExpress grid controls that are bound to Server or Instant Feedback data sources cannot sort, group and filter by columns bound to in-memory or runtime values. Unlike client mode, grids in Server or Instant Feedback Modes delegate all data manipulation operations to the underlying data layer (XPO, EF, LINQ to SQL, etc), which in turn constructs appropriate SQL statements and runs queries against supported database servers to retrieve small portions of data for the best speed and memory consumption (learn more…).
How To Handle Invalid Operations Against In-Memory Values
Sort, group and filter operations by grid columns bound to in-memory values that physically do not exist in the database should normally be disabled in Server or Instant Feedback Modes. To warn developers about invalid operations against database servers, XPO may throw the "Cannot query a data store using criterion (…)" error. To avoid this error, do one of the following:
1. Explicitly disable invalid operations at the grid control level (if it is impossible to express calculated column values via database values)
- Set AllowXXX column options to False (for instance, in WinForms GridControl you can use AllowSort , AllowGroup, AllowFilter, AllowAutoFilter, etc.)…
- Exclude the corresponding columns from the Find Panel filter (for instance, in WinForms GridControl you can use GridView.OptionsFind.FindFilterColumns).
NOTE: XAF Grid List Editors automatically disables database server-side operations for non-persistent properties when DataAccessMode != Client. For more information, see PreventServerSideOperationsForNonPersistentMembers and S31714.
2. Express calculated column values via database values
In certain cases, C# or VB.NET logic in getters of calculated properties can be expressed using database fields or database functions.
- Implement calculated properties in XPO classes with PersistentAliasAttribute.
- If it is not possible to modify your XPO class code, implement calculated column at the grid control level with Unbound Expressions: WinForms, WPF and ASP.NET.
See Also
Server Mode Limitations (WinForms)
Server Mode Limitations (WPF)
Server Mode Limitations (ASP.NET WebForms)
Hello guys,
I use the controller provide by Dennis and I use this method instead of the IsPersistent method :
private bool LectureSeule(XafGridColumnWrapper column) { System.Reflection.PropertyInfo proper = typeof(MyClass).GetProperty(column.PropertyName); if (proper == null) return false; return !proper.CanWrite; }
It's OK for the filtering, sorting and grouping in the gridview.
But I have another problem, the property is always accessible in the "Filter Editor", so how can I deactivate my property (or all properties that are read-onl/non-persistent) in the "Filter Editor" ?
It's OK guys, I find my answers in the ticket T342565.
@Gilles Brice Mahabo: We are happy to hear of your results. I have also updated my answer to mention related XAF changes in v16.2.6/17.1.3.