Ticket S171635
Visible to All Users

Filtering - Create a built-in criteria function to check if an XPO object is new or saved

created 12 years ago (modified 11 years ago)

This criteria function will be very helpful for ConditionalAppearance and Validation rules as well as for the Action's TargetObjectsCriteria property, because it will help avoid writing a lot of routine code.
For instance, currently it is necessary to either introduce a hidden calculated property in the business class for further use in the criteria:

C#
public bool IsNewObject { get { return Session.IsNewObject(this, false); } }

or create a Controller and manually execute some code (e.g., disable or deactivate an Action) agains tthe IObjectSpace.IsNewObject result.

Proposed usage of the built-in IsNewObject criteria function in the criteria string:  "IsNewObject(This)" or "IsNewObject(Manager)"

Comments (2)

    Yes, yes, yes, a thousand times, yes!

      ok,ok, I have this property in my BaseObject since XAF exists (7 years or so?) and then just forgot that it is not built in.

      Answers approved by DevExpress Support

      created 11 years ago (modified 5 years ago)

      We have implemented the functionality described in this ticket. It will be included in our next update(s).

      Please check back and leave a comment to this response to let us know whether or not this solution addresses your concerns.

      Additional information:

      We have implemented the IsNewObject(obj)  Function Criteria Operator. It is applicable to XPO objects only. The operator indicates whether a specified object has been created but has not been saved to the database. The Evaluate method of this operator gets the current Object Space via the static XPObjectSpace.FindObjectSpaceByObject method and then returns the XPObjectSpace.IsNewObject result. In case the Object Space is not found, the operator returns false. The operator can be evaluated at the client side only and should not be used in security permissions criteria.
      Refer to the Checking if an object is new or not within a criterion string  blog post to learn more on popular scenarios where this new functionality can be applied in your projects.

      Examples:

      IsNewObject(This)
      IsNewObject(Manager)

      UPDATE:
      In v20.1, the IsNewObject function (IsNewObjectCriteriaOperator) works both for XPO persistent objects and for objects that implement the [IObjectSpaceLink][0] interface. This interface can be implemented in Entity Framework classes and Non-Persistent object classes.

        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.