Skip to main content
All docs
V24.1

Map Persistent Objects to Database Views

  • 2 minutes to read

Create a Persistent Class

Create a persistent class. The class name should match the view name.

Assign the Persistent attribute to the persistent class if its name differs from the view name (see the example below).

[Persistent("DatabaseViewName")]
public class MyView : XPLiteObject {  

} 

Important

The Persistent attribute is case sensitive.

Create a Primary Key

To work correctly with an existing database view, the view must have a field with unique values (the key field). Create a persistent property with the same name as the view’s key field, and assign the Key attribute to it.

If the view does not have a field with unique values, create a composite key as shown in the following example.

public struct MyViewKey {  
    [Persistent("FirstColumn")]  
    public string FirstColumn;  
    [Persistent("SecondColumn")]  
    public string SecondColumn; 
} 

[Persistent("DatabaseViewName")]
public class MyView : XPLiteObject {  
    [Key, Persistent]  
    public MyViewKey Key;  

    [PersistentAlias("Key.FirstColumn")]  
    public string FirstValue { get { return Key.FirstColumn; } }  
    [PersistentAlias("Key.SecondColumn")]  
    public string SecondValue { get { return Key.SecondColumn; } }  
} 

Create Persistent Properties

Create public persistent properties for all data fields or specific fields. The type of persistent properties must match the type of the corresponding fields in the database view.

See Also