Ticket T416738
Visible to All Users

Override properties of business objects

created 9 years ago

[DevExpress Support Team: CLONED FROM K18270: Can I override properties of business objects?]
Hello,
I have 2 questions:

>>When you override a property of the base class, it can cause a mismatch between the database and business classes. A column is already created in the database table for the virtual property. Overridden properties use the same column and cannot modify their parameters. So, there is no point in applying attributes from the DevExpress.Xpo namespace to overridden properties.

  1. What if the base class is nonpersistent or abstract? Since it involve nothing to the database,could it probably be excepted in the future?

  2. If overriding is not recommended, What is the recommended way to centralize common logic from several classes?

Thank you

Answers approved by DevExpress Support

created 9 years ago (modified 9 years ago)

Hello Paul,

  1. As far as I understand, you are asking about attributes. We do not have immediate plans to support applying different attributes to parent and descendant classes. I have passed your idea to our developers through, and we will take it into account in the future.

  2. You can use methods for this purpose. There are several built-in methods where business logic can be defined - OnSaving, AfterConstruction, OnChanged, etc. In addition, you can declare custom virtual methods, use them in property getters and setters and override them in descendants if required.

If this information is insufficient, please describe the task you need to implement in greater detail.

    Show previous comments (2)
    Anatol (DevExpress) 9 years ago

      Have you considered declaring validation rules in the Application Model? Refer to the Implement Property Value Validation in the Application Model topic for additional information. Besides the Model Editor, you can also declare such rules in code using a ModelNodesGeneratorUpdater for the ModelValidationRulesNodeGenerator.
      In addition, a lot of property-level validation rules can be replaced with class-level rules, such as RuleCriteria and RuleObjectExists.

        Thank you, Anatol.

        >>Furthermore, I still don't know how to change a static value 999999.99 into a global variable since C# Attribute Parameter doesn't allow. This will introduce a Ctrl+F in all source code, replace and recompile solution in a future. -ugh.

        Now my implementation end up with  :

        1. replacing a 99999.99 with custom attribute + static string property

        C#
        [DecimalType(DecimalType.Amount)] public decimal Credit { get set }
        1. using E729 to introduce a persistent "CustomRuleRange" implementing IruleSource.
        C#
        public class CustomRuleRange : XPLiteObject, IRuleSource { }
        1. Introducing a persistent "MyVariable" to store a dynamic min/max value and override the OnSaving event
        C#
        //persistent "MyVariable" class public decimal AmtMin { get set } public decimal AmtMax { get set } protected override void OnSaving() { base.OnSaving(); XPCollection<CustomRuleRange> CustomRuleRanges = new XPCollection<CustomRuleRange>(...); foreach (CustomRuleRange cRule in CustomRuleRanges) { cRule.MinimumValue = AmtMin; cRule.MaximumValue = AmtMax; } }

        as a result, users can edit their desired range through the MyVariable and it will affect to all CustomRuleRange objects that also affect to the Application Model via its CreateRule() method.
        This way I can also get rid of multiple RuleRangeAttribute hardcoded in a BO. This solution is perfect to me.

        Thank you again.

        Anatol (DevExpress) 8 years ago

          I am happy to hear that you have found an appropriate solution. Thank you for sharing your code.

          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.