Giter VIP home page Giter VIP logo

xpo-how-to-implement-self-referenced-persistent-objects-and-display-them-within-the-xtra-tree-list's Introduction

XPO - How to implement self-referenced persistent objects and display them within the XtraTreeList

This example demostrates how to implement self-referenced persistent objects and display them within the XtraTreeList. A simple example of a self-referenced object is an Employee. An employee reports to a Manager, but at the same time, this employee might also be a manager for other employers, referred to as Subordinates.

A self-referenced object has a parent object property and a child collection. Here is the persistent Employee class. It has a Manager property of type Employee and Subordinates of type XPCollection<Employee>. Both properties are decorated with the Association attribute. As such, the Employee type appears on both sides of a one-to-many association.

C#

using DevExpress.Xpo;  

public class Employee : XPObject {  
    public Employee(Session session) : base(session) { }  

    string _FullName;  
    public string FullName {  
        get { return _FullName; }  
        set { SetPropertyValue("FullName", ref _FullName, value); }  
    }  

    private string _Title;  
    public string Title {  
        get { return _Title; }  
        set { SetPropertyValue("Title", ref _Title, value); }  
    }  

    Employee _Manager;  
    [Association("ManagerSubordinates")]  
    public Employee Manager {  
        get { return _Manager; }  
        set { SetPropertyValue("Manager", ref _Manager, value); }  
    }  

    [Association("ManagerSubordinates")]  
    public XPCollection<Employee> Subordinates {  
        get { return GetCollection<Employee>("Subordinates"); }  
    }  
}  

VB

Imports DevExpress.Xpo  

Public Class Employee  
    Inherits XPObject  
    Public Sub New(ByVal session As Session)  
        MyBase.New(session)  
    End Sub  

    Private _FullName As String  
    Public Property FullName() As String  
        Get  
            Return _FullName  
        End Get  
        Set(ByVal value As String)  
            SetPropertyValue("FullName", _FullName, value)  
        End Set  
    End Property  

    Private _Title As String  
    Public Property Title() As String  
        Get  
            Return _Title  
        End Get  
        Set(ByVal value As String)  
            SetPropertyValue("Title", _Title, value)  
        End Set  
    End Property  

    Private _Manager As Employee  
    <Association("ManagerSubordinates")> _  
    Public Property Manager() As Employee  
        Get  
            Return _Manager  
        End Get  
        Set(ByVal value As Employee)  
            SetPropertyValue("Manager", _Manager, value)  
        End Set  
    End Property  

    <Association("ManagerSubordinates")> _  
    Public ReadOnly Property Subordinates() As XPCollection(Of Employee)  
        Get  
            Return GetCollection(Of Employee)("Subordinates")  
        End Get  
    End Property  
End Class  

A collection of self-referenced objects can be displayed in the XtraTreeList. TreeList properties must be set as shown below.
C#

treeList1.KeyFieldName = "This";  
treeList1.ParentFieldName = "Manager!";  
treeList1.RootValue = null;  
treeList1.DataSource = xpCollection1;  

VB

treeList1.KeyFieldName = "This"  
treeList1.ParentFieldName = "Manager!"  treeList1.RootValue = Nothing  
treeList1.DataSource = xpCollection1  

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

xpo-how-to-implement-self-referenced-persistent-objects-and-display-them-within-the-xtra-tree-list's People

Contributors

andreykozhevnikov avatar devexpressexamplebot avatar nikolaevairina avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.