Skip to main content
All docs

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).

public class MyView : XPLiteObject {  



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 {  
    public string FirstColumn;  
    public string SecondColumn; 

public class MyView : XPLiteObject {  
    [Key, Persistent]  
    public MyViewKey Key;  

    public string FirstValue { get { return Key.FirstColumn; } }  
    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