Skip to main content
All docs
V24.2
.NET 8.0+

XAF0020: Avoid applying NonPersistentAttribute to properties without a public setter

Severity: Warning

The NonPersistentAttribute is redundant for read-only properties (non-public or missing setters). Apply the attribute only to writeable properties if you do not want their values to persist in a data store.

Examples

Invalid Code

[NonPersistent]
public Topic Topic {
     get { return fTopic; }
}
Topic fTopic;

// OR

[NonPersistent]
public Topic Topic {
    get { return fTopic; }
    private set { SetPropertyValue(nameof(Topic), ref fTopic, value); }
}
Topic fTopic;

Valid Code

public Topic Topic {
    get { return fTopic; }
}
Topic fTopic;

// OR

public Topic Topic {
    get { return fTopic; }
    private set { SetPropertyValue(nameof(Topic), ref fTopic, value); }
}

// OR

[NonPersistent]
public AnyType Topic {
    get { return fTopic; }
    set { SetPropertyValue(nameof(Topic), ref fTopic, value); }
}
AnyType fTopic;