Current filter:
                                You should refresh the page.
                                  • Description:
                                    According to the business logic of my application, a particular property of a persistent object must be read-only. Its value should be set when the object is created and then never changed. However, this property must also be persistent. How to define a read-only persistent property in an XPO class?

                                    You should create a property which doesn't have a "setter" method in your class (and, if you are coding in VB.NET, put the ReadOnly keyword in the property's definition). Such a property is non-persistent by default. To be able to use this property in filter criteria, search by it or include it in the XPCollection.DisplayableProperties, the property must be marked with the PersistentAlias attribute.
                                    A real value may be stored in a private field. Private fields are also non-persistent members of an XPObject. You should add the Persistent attribute to the field with the name of the read-only property. This name will be used for the column's name in the database table corresponding to your object.
                                    A value for a read-only property can be passed as a parameter in the object's constructor. Thus, a value can be specified only for a new object and cannot be changed afterwards.

                                    public class Client : XPObject { [Persistent("ClientID")] private string clientID; [PersistentAlias("clientID")] public string ClientID { get { return clientID; } } public Client(string clientID) { this.clientID = clientID; } public Client(Session session) : base(session) {} }

                                    Note You can make your object's property "read-only" just for bound visual controsl, e.g. TextEdit. All you need is to decorate your property or public field with the ReadOnly attribute as explained in the following article:
                                    How to prevent an object's property from being edited in data bound controls
                                    See Also:
                                    A2958 - How to prevent XPO from making any changes to a legacy database
                                    K18014 - How to make a delayed persistent property read-only

                                0 Solutions

                                Creation Date Importance Sort by