Ticket T744618
Visible to All Users

How to override persistent properties

created 6 years ago

[DevExpress Support Team: CLONED FROM T548158: Defining Member Permissions on an descendant class with a property overridden using K18270 approach, a duplicate key exception is thrown]
Hi @Uriah is there a solution to this beyond saying the approach is outdated?  I have a legitimate need for this where I have a concept of Quote, QuoteItem and QuoteProductItem. The only difference with QuoteProductItem is that it links to a Product whereas the QuoteItem does not.  What I want to have is if you set a SKU on the QuoteProductItem (which also exists on QuoteItem) it should automatically set the Product reference to the Product that matches the SKU.  I'm running into same problem as Alex.

Comments (3)
DevExpress Support Team 6 years ago

    Hello,

    >> What I want to have is if you set a SKU on the QuoteProductItem (which also exists on QuoteItem) it should automatically set the Product reference to the Product that matches the SKU.

    You can achieve this result without inheritance. Please check the following code and let me know if this solution meets your requirements.

    C#
    public class QuoteProductItem :XPObject { private Product fProduct; public Product Product { get => fProduct; set => SetPropertyValue(nameof(Product), ref fProduct, value); } private SKU fSku; public SKU SKU { get => fSku; set { bool modified = SetPropertyValue(nameof(SKU), ref fSku, value); if (modified && !IsLoading) Product = SKU.Product; } } }

      Hi @Uriah, No, that doesn't work. As QuoteProductItem needs to inherit QuoteItem as it has many other shared fields. So QuoteProductItem : QuoteItem.

      DevExpress Support Team 6 years ago

        Thank you for the clarification. If the SKU property is a QuoteItem member, you can use the virtual OnChanged method to update the Product property. I have provided a code snippet in the answer. Please check if this solution meets your requirements.

        Answers approved by DevExpress Support

        created 6 years ago (modified 6 years ago)

        If the SKU property is a QuoteItem member, you can use the virtual OnChanged method to update the Product property.

        C#
        public class QuoteItem : XPObject { private SKU fSku; public SKU SKU { get => fSku; set { bool modified = SetPropertyValue(nameof(SKU), ref fSku, value); if (modified && !IsLoading) Product = SKU.Product; } } } public class QuoteProductItem : QuoteItem { private Product fProduct; public Product Product { get => fProduct; set => SetPropertyValue(nameof(Product), ref fProduct, value); } protected override void OnChanged(string propertyName, object oldValue, object newValue) { base.OnChanged(propertyName, oldValue, newValue); if (propertyName == nameof(SKU)) { Product = SKU.Product; } } }
          Comments (2)

            Thanks Uriah, that's a nice clean solution for what I'm trying to achieve. I was trying to override the SKU with new keyword and then went down the path of itroducing another property which isn't necessary with this approach.

            DevExpress Support Team 6 years ago

              You are welcome, Sheldmandu!

              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.