How to define a read-only persistent property

In accordance with the business logic of my application, a specific property of a permanent object should be read-only. Its value must be set when the object is created, and then does not change. However, this property must also be constant. How to define a read-only persistent property in an XPO class?

+4
source share
2 answers

You must create a property that does not have a "setter" method in your class (and if you code in VB.NET, put the ReadOnly keyword in the property definition). By default, this property is volatile. In order to be able to use this property in filter criteria, search for it or include it in XPCollection.DisplayableProperties, the property must be marked with the PersistentAlias ​​attribute.

The actual value can be stored in a private field. Private fields are also non-persistent XPObject members. You must add the Persistent attribute to the field with the name of the read-only property. This name will be used for the column name in the database table corresponding to your object.

, , . , .

+4
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) {}
}

. " " controsl, . TextEdit. , , - ReadOnly

+1

Source: https://habr.com/ru/post/1696274/


All Articles