in
Forums
Blogs
Files
Devexpress.Com
Client Center
Support Center
DevExpress Channel

Many-to-Many (Same Object)

Last post 11/6/2008 10:17 AM by csom. 3 replies.
Page 1 of 1 (4 items)
Sort Posts:
Previous Next
  • 10/30/2008 1:04 PM

    • csom
    • Not Ranked
    • Joined on 5/10/2008
    • Switzerland
    • Posts 5

    Many-to-Many (Same Object)

    Hello,

    can someone tell me how I can etablish a many-to-many relationship to the same object? Is that possible?

    I have a class called "Component" which has two properties (name, and components).

    A component can contain other components and therefor a component can be included in other components (many-to-many).

    I hope you understand what i try to do. Big Smile

    Any help would be nice.

    Thanks Claudio

  • 10/30/2008 3:34 PM In reply to

    • Jim Clay
    • Top 200 Contributor
    • Joined on 1/14/2008
    • Sandpoint, ID
    • Posts 57

    Re: Many-to-Many (Same Object)

     Here is a link to a KB that shows you how to implement self-referenced persistent objects:

    http://www.devexpress.com/Support/Center/KB/p/K18072.aspx

    It also talks about displaying them in a tree list if that is of any interest.

    Jim

  • 10/30/2008 9:26 PM In reply to

    Re: Many-to-Many (Same Object)

    Answer

    This KB article talks about a 1:N relation while the OP asked for a M:N relation.

    Try this:
    public class Component : XPObject
    {
        public Component(Session session) : base(session) { }
     
        private string _name;
        public string Name
        {
            get { return _name; }
            set { SetPropertyValue<string>("Name", ref _name, value); }
        }
     
        [Association("IsPartOf:Parts")]
        public XPCollection<Component> IsPartOf
        {
            get { return GetCollection<Component>("IsPartOf"); }
        }
     
        [Association("IsPartOf:Parts")]
        public XPCollection<Component> Parts
        {
            get { return GetCollection<Component>("Parts"); }
        }
    }
     
    HTH, Robert
     
  • 11/6/2008 10:17 AM In reply to

    • csom
    • Not Ranked
    • Joined on 5/10/2008
    • Switzerland
    • Posts 5

    Re: Many-to-Many (Same Object)

    Thank you Robert. That solved my problem.

Page 1 of 1 (4 items)
Copyright © 1998-2008 Developer Express Inc.
ALL RIGHTS RESERVED