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

One way Associations - The easy way...

Last post 11/18/2008 6:26 AM by Niek Hulsman. 0 replies.
Page 1 of 1 (1 items)
Sort Posts:
Previous Next
  • 11/18/2008 6:26 AM

    One way Associations - The easy way...

    Reposting this snippet for people who want to make an association on one side of the chain:

    I made this code a year ago. It isn't tested and i haven't used it in production, but it seems to work fine. It enables you to create an association on one end of the chain while not worrying about the other end. Like this:

        public class ClPerson : XPObject {
            #region Constructors

            public ClPerson() {
            }

            public ClPerson(Session session)
                : base(session) {
            }

            #endregion
           
            #region Fields

            private String m_name;
            private ClAddress m_addressMtO;

            #endregion

            #region Properties

            public String Name {
                get { return m_name; }
                set { m_name = value; }
            }

            #endregion    

            #region Associations

            [OneToMany, Association("AddressesOtM", typeof(ClAddress))]
            public XPCollection<ClAddress> AddressesOtM {
                get { return GetCollection<ClAddress>("AddressesOtM"); }
            }
           
            [ManyToMany, Association("AddressesMtM", typeof(ClAddress))]
            public XPCollection<ClAddress> AddressesMtM {
                get { return GetCollection<ClAddress>("AddressesMtM"); }
            }

            public ClAddress AddressesMtO {
                get { return m_addressMtO; }
                set { m_addressMtO = value; }
            }

            #endregion
        }

     

     

        public class ClAddress : XPObject {
            #region Constructors

            public ClAddress() {
            }

            public ClAddress(Session session)
                : base(session) {
            }

            #endregion

            #region Fields

            private String m_street;

            #endregion

            #region Properties

            public String Street {
                get { return m_street; }
                set { m_street = value; }
            }

            #endregion               
        }

     

    You gonna have to assign the custom made IXReflectionDictionary when the program starts up like this: XpoDefault.Dictionary = new IXReflectionDictionary();

    I've posted the code in this topic: http://community.devexpress.com/forums/p/65308/222111.aspx#222111

    A sample is provided.

     

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