KB Article T523335
Visible to All Users

XPQuery changes regarding non-persistent properties in v17.1

In version 17.1, we have improved error detection in XPQuery when non-persistent properties are used in it. Previously, such queries didn't work (either failed with various exceptions or worked incorrectly) and thus there were hidden errors in your programs. Now, we throw an exception that describes which non-persistent properties are used in XPQuery to help diagnosing these errors. If such properties are used intentionally, consider implementing them using PersistentAliasAttribute or adding the ToList method call to explicitly process these properties on the client side.

For example, the following code now throws an exception:

C#
public class Person: XPObject { string _firstName; public string FirstName { get { return _firstName; } set { SetPropertyValue("FirstName", ref _firstName, value); } } string _lastName; public string LastName { get { return _lastName; } set { SetPropertyValue("LastName", ref _lastName, value); } } public string NonPersistentProperty { get { return FirstName + " " + LastName; } } } //... var query = new XPQuery<Person>(uow).Where(p => p.FirstName == "John" && p.NonPersistentProperty.Contains("Jr"))
Visual Basic
Public Class Person Inherits XPObject Private _firstName As String Public Property FirstName() As String Get Return _firstName End Get Set(ByVal value As String) SetPropertyValue("FirstName", _firstName, value) End Set End Property Private _lastName As String Public Property LastName() As String Get Return _lastName End Get Set(ByVal value As String) SetPropertyValue("LastName", _lastName, value) End Set End Property Public ReadOnly Property NonPersistentProperty() As String Get Return FirstName & " " & LastName End Get End Property End Class '... Dim query = (New XPQuery(Of Person)(uow)).Where(Function(p) p.FirstName = "John" AndAlso p.NonPersistentProperty.Contains("Jr"))

It can be fixed by rewriting the query with the ToList method to process a part of the query on the client side:

C#
var query = new XPQuery<Person>(uow).Where(p => p.FirstName == "John").ToList().Where(p => p.NonPersistentProperty.Contains("Jr"));
Visual Basic
Dim query = (New XPQuery(Of Person)(uow)).Where(Function(p) p.FirstName = "John").ToList().Where(Function(p) p.NonPersistentProperty.Contains("Jr"))

It can also be fixed by implementing the property using PersistentAliasAttribute:

C#
public class Person : XPObject { //... [PersistentAlias("Concat(FirstName, ' ', LastName")] public string NonPersistentProperty { // It is persistent now get { return (string)EvaluateAlias("NonPersistentProperty"); } } }
Visual Basic
Public Class Person Inherits XPObject '... <PersistentAlias("Concat(FirstName, ' ', LastName")> Public ReadOnly Property NonPersistentProperty() As String ' It is persistent now Get Return CStr(EvaluateAlias("NonPersistentProperty")) End Get End Property End Class

Since rewriting many queries in an existing application can be a tedious task, starting with version 17.1.6 we implemented the static XPQueryBase.SuppressNonPersistentPropertiesCheck property. Set this property to True (at the application start) to revert to the old behavior. Note that when this property is set, an exception still can be thrown in scenarios that were never supported, but at a later stage.

Search keywords: NotSupportedException, InvalidOperationException,  LINQ, 17.1, XPQuery<T>, "The expression is not supported in the Where/OrderByXXX clause"

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.