Skip to main content
A newer version of this page is available. .
All docs
V22.2
.NET Framework 4.5.2+

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;