Forums

Problem with 0/1-N relations defined in a abstract class.

Last post 7/6/2009 4:30 PM by Frans de Wit. 10 replies.
Sort Posts: Previous Next
  • Frans de Wit

    Problem with 0/1-N relations defined in a abstract class.

    7/3/2009 10:41 AM
    • Not Ranked
    • Joined on 6/19/2009
    • Posts 18

     

    All,

    Please can someone help me with this problem. I am creating a XPO class generator that takes a database (I will call it the ERD) and from it creates a set of classes. Abstract classes to define the database and non-abstract classes to contain meta data and business rules. All meta data to create the XPO classes with virtual properties, default values, null able values, aggregated fields, locking schemas etc. etc. is taken from the ERD, the idea here is that the ERD is leading (and thus the database) and not the XPO classes.

    There is one thing I cannot get working, is I define a 0/1-N relation in the abstract class, then the runtime will create the database, but it will trip with an error. The error is:

    failed: DevExpress.Xpo.Exceptions.AssociationInvalidException : There is a malformed association 'FK_Child_FK_Parent'. Cannot find the associated member for 'Profix.UltraSimple.Database.AChild.Parent' in the class 'Profix.UltraSimple.Database.Parent'

           at DevExpress.Xpo.Metadata.XPMemberInfo.GetAssociatedMember()

           at DevExpress.Xpo.Metadata.XPMemberInfo.ProcessAssociationRefChange(Session session, Object referenceMemberOwner, Object oldValue, Object newValue, Boolean skipNonLoadedCollections)

           at DevExpress.Xpo.Session.TriggerObjectChanged(Object changedObject, ObjectChangeEventArgs e)

           C:\Work\VS_ProfixXpoTools\ConsoleBasedXpoGenData\UltraSimple\Generated.All\AChild.cs(677,0): at Profix.UltraSimple.Database.AChild.set_Parent(Parent value)

           C:\Work\VS_ProfixXpoTools\ConsoleBasedXpoGenData\UltraSimple\UnitTestUltraSimple.cs(32,0): at Profix.UnitTestsUltraSimple.CreateCTest()

     

    Has anyone any idea how to make this work? That is: define the relation in the abstract class with the types (in the relation) referring to the non-abstract class.

    The code defining the relations is:

    In the class Child:

            // GetAbstractGenAssociation0NsGetSetMember

            [DevExpress.Xpo.PersistentAttribute(Profix.UltraSimple.Database.Child.ForeignKeys.Parent)]

            [DevExpress.Xpo.AssociationAttribute(Profix.UltraSimple.Database.Parent.Associations.ChildListByParent, typeof(Profix.UltraSimple.Database.AParent))]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(true)]

            public Parent Parent

            {

                get

                {

                    return this._fkParent;

                }

                set

                {

                    if (this._fkParent != value)

                    {

                        Parent fkParent = this._fkParent;

                        this._fkParent = value;

                        this.OnChanged(Profix.UltraSimple.Database.Child.Properties.Parent, fkParent, this._fkParent);

                    }

                }

            }

     

    In the class Parent:

            // GetAbstractGenAssociation0NsGetCollections

            [DevExpress.Xpo.AssociationAttribute(Profix.UltraSimple.Database.Parent.Associations.ChildListByParent, typeof(Profix.UltraSimple.Database.AChild))]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(true)]

            public DevExpress.Xpo.XPCollection<Profix.UltraSimple.Database.Child> ChildListByParent

            {

                get

                {

                    DevExpress.Xpo.XPCollection<Profix.UltraSimple.Database.Child> aoChildListByParent

                        = this.GetCollection<Profix.UltraSimple.Database.Child>(Profix.UltraSimple.Database.Parent.Properties.ChildListByParent);

                    return aoChildListByParent;

                }

            }

     

    All code needed to make the data objects workable follows (7 source files).

    Regards,

    Frans de Wit

    BTW: For anyone interested, I am willing to make this an open source project. With sufficient interest I will create a project on ‘www.codeplex.com’.

    using System;

    using DevExpress.Xpo;

     

    namespace Profix

    {

        public class ProfixSession

        {

            public static Session DefaultSession

            {

                get

                {

                    return Session.DefaultSession;

                }

            }

        }

     

        public interface IProfixXPCustomObject

        {

            bool IsNew

            {

                get;

            }

     

            bool IsConstructionFinished

            {

                get;

            }

        }

     

        [NonPersistent]

        public abstract class AProfixXPCustomObject : XPCustomObject

        {

            public AProfixXPCustomObject(Session poSession)

                : base(poSession)

            {

            }

        }

    }

     

    using System;

     

    // === ============================================================ ===

    // === Generator: GetAbstractGen                                    ===

    // === GenDate  : 7/3/2009 4:14:14 PM                               ===

    // === Version  : 0.0.0.4(Beta)                                     ===

    // === ============================================================ ===

     

    namespace Profix.UltraSimple.Database

    {

        [DevExpress.Xpo.PersistentAttribute("Parent")]

        [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(false)]

        public abstract class AParent : Profix.AProfixXPCustomObject, Profix.IProfixXPCustomObject

        {

            #region Protected

     

            // GetAbstractGenProtectedOverrideVoidOnSaving

            protected override void OnSaving()

            {

                if (this.IsNew)

                {

                    if (this.IsConstructionFinished && (this._guidOid == Guid.Empty))

                        this._guidOid = DevExpress.Xpo.XpoDefault.NewGuid();

                }

                base.OnSaving();

            }

     

            #endregion // Protected

     

            #region Internal

     

            #endregion // Internal

     

            #region Private

     

            private int _nIsNew;

            private bool _lIsConstructionFinished;

     

            // GetAbstractGenPrivateFields(1)

            [DevExpress.Xpo.KeyAttribute(true)]

            [DevExpress.Xpo.PersistentAttribute("PK")]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(false)]

            [System.ComponentModel.BrowsableAttribute(false)]

            private Guid _guidOid;

     

            // GetAbstractGenPrivateFields(2)

            private string _sText;

     

            #endregion // Private

     

            #region Public

     

            // GetAbstractGenConstructor1AllColumnsInclusiveDefaults

            public AParent(

                  DevExpress.Xpo.Session poSession

                , string psText)

                : base(poSession)

            {

                this.Text = psText;

            }

     

            // GetAbstractGenConstructor5OnlyTheSessionParameter

            public AParent(DevExpress.Xpo.Session poSession)

                : base(poSession)

            {

            }

     

            // GetAbstractGenPublicGetOid

            [DevExpress.Xpo.PersistentAliasAttribute("_guidOid")]

            [System.ComponentModel.BrowsableAttribute(false)]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(true)]

            public Guid Oid

            {

                get

                {

                    if (this.IsNew && this.IsConstructionFinished && (this._guidOid == Guid.Empty))

                        this._guidOid = DevExpress.Xpo.XpoDefault.NewGuid();

                    return this._guidOid;

                }

            }

     

            // GetAbstractGenGettersAndSetters(1)

            [DevExpress.Xpo.SizeAttribute(50)]

            [DevExpress.Xpo.DbTypeAttribute("nchar(50)")]

            [DevExpress.Xpo.PersistentAttribute(Profix.UltraSimple.Database.Parent.Properties.Text)]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(true)]

            public string Text

            {

                get

                {

                    return this._sText;

                }

                set

                {

                    if (this._sText != value)

                    {

                        string sText = this._sText;

                        this._sText = value;

                        this.OnChanged(Profix.UltraSimple.Database.Parent.Properties.Text, sText, this._sText);

                    }

                }

            }

     

            // GetAbstractGenAssociation0NsGetCollections

            [DevExpress.Xpo.AssociationAttribute(Profix.UltraSimple.Database.Parent.Associations.ChildListByParent, typeof(Profix.UltraSimple.Database.AChild))]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(true)]

            public DevExpress.Xpo.XPCollection<Profix.UltraSimple.Database.Child> ChildListByParent

            {

                get

                {

                    DevExpress.Xpo.XPCollection<Profix.UltraSimple.Database.Child> aoChildListByParent

                        = this.GetCollection<Profix.UltraSimple.Database.Child>(Profix.UltraSimple.Database.Parent.Properties.ChildListByParent);

                    return aoChildListByParent;

                }

            }

     

            public override void AfterConstruction()

            {

                base.AfterConstruction();

                this._lIsConstructionFinished = true;

            }

     

            [DevExpress.Xpo.NonPersistentAttribute()]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(false)]

            public bool IsNew

            {

                get

                {

                    if (this._nIsNew == 0)

                        this._nIsNew = base.Session.IsNewObject(this) ? 2 : 1;

                    return this._nIsNew == 2;

                }

            }

     

            [DevExpress.Xpo.NonPersistentAttribute()]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(false)]

            public bool IsConstructionFinished

            {

                get

                {

                    return this._lIsConstructionFinished;

                }

            }

     

            #endregion // Public

        }

    }

     

    using System;

     

    // === ============================================================ ===

    // === Generator: GetImplementationGen                              ===

    // === GenDate  : 7/3/2009 4:14:14 PM                               ===

    // === Version  : 0.0.0.4(Beta)                                     ===

    // === ============================================================ ===

     

    namespace Profix.UltraSimple.Database

    {

        [DevExpress.Xpo.MapInheritanceAttribute(DevExpress.Xpo.MapInheritanceType.ParentTable)]

        [DevExpress.Xpo.DeferredDeletionAttribute(true)]

        [DevExpress.Xpo.OptimisticLockingAttribute(true)]

        [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(true)]

        public partial class Parent : AParent

        {

            #region Protected

     

            #endregion // Protected

     

            #region Internal

     

            #endregion // Internal

     

            #region Private

     

            #endregion // Private

     

            #region Public

     

            // GetImplementationGenPublicStaticClassAssociations

            public static class Associations

            {

                public const string ChildListByParent = "FK_Child_FK_Parent";

            }

     

            // GetImplementationGenPublicStaticClassFields(1)

            public static DevExpress.Xpo.PersistentBase.FieldsClass BaseFields

            {

                get { return DevExpress.Xpo.PersistentBase.Fields; }

            }

     

            // GetImplementationGenPublicStaticClassFields(2)

            public new static class Fields

            {

                public static DevExpress.Data.Filtering.OperandProperty Text { get { return new DevExpress.Data.Filtering.OperandProperty(Profix.UltraSimple.Database.Parent.Properties.Text); } }

            }

     

            // GetImplementationGenPublicStaticClassProperties

            public static class Properties

            {

                public const string Text = "Text";

                public const string ChildListByParent = "ChildListByParent";

            }

     

            // GetImplementationGenConstructor1AllColumnsInclusiveDefaults

            public Parent(

                  DevExpress.Xpo.Session poSession

                , string psText)

                : base(poSession, psText)

            {

            }

     

            // GetImplementationGenConstructor5OnlyTheSessionParameter

            public Parent(DevExpress.Xpo.Session poSession)

                : base(poSession)

            {

            }

     

            // GetImplementationGenConstructor6ObsoleteNoSessionParameter

            [System.ObsoleteAttribute("Constructor only to be used for deserialization", true)]

            public Parent()

                : base(Profix.ProfixSession.DefaultSession)

            {

            }

     

            #endregion // Public

        }

    }

     

    using System;

     

    // === ============================================================ ===

    // === Generator: GetImplementationImp                              ===

    // === GenDate  : 7/2/2009 3:19:00 PM                               ===

    // === Version  : 0.0.0.4(Beta)                                     ===

    // === ============================================================ ===

     

    namespace Profix.UltraSimple.All.Database

    {

        public partial class Parent

        {

            #region Protected

     

            #endregion // Protected

     

            #region Internal

     

            #endregion // Internal

     

            #region Private

     

            #endregion // Private

     

            #region Public

     

            #endregion // Public

        }

    }

     

    using System;

     

    // === ============================================================ ===

    // === Generator: GetAbstractGen                                    ===

    // === GenDate  : 7/3/2009 4:14:14 PM                               ===

    // === Version  : 0.0.0.4(Beta)                                     ===

    // === ============================================================ ===

     

    namespace Profix.UltraSimple.Database

    {

        [DevExpress.Xpo.PersistentAttribute("Child")]

        [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(false)]

        public abstract class AChild : Profix.AProfixXPCustomObject, Profix.IProfixXPCustomObject

        {

            #region Protected

     

            // GetAbstractGenProtectedOverrideVoidOnSaving

            protected override void OnSaving()

            {

                if (this.IsNew)

                {

                    if ((this._lLocalMemo1 == false) && (this._lSavedMemo1 == false))

                        this.Memo1 = this._sMemo1;

                    if ((this._lLocalMemo2 == false) && (this._lSavedMemo2 == false))

                        this.Memo2 = this._sMemo2;

                    if (this._lSavedMemo5 == false)

                        this.Memo5 = this._lLocalMemo5 ? this._sMemo5 : Profix.UltraSimple.Database.Child.Defaults.Memo5;

                    if (this._lSavedMemo6 == false)

                        this.Memo6 = this._lLocalMemo6 ? this._sMemo6 : Profix.UltraSimple.Database.Child.Defaults.Memo6;

                    if (this.IsConstructionFinished && (this._guidOid == Guid.Empty))

                        this._guidOid = DevExpress.Xpo.XpoDefault.NewGuid();

                }

                base.OnSaving();

            }

     

            #endregion // Protected

     

            #region Internal

     

            #endregion // Internal

     

            #region Private

     

            private int _nIsNew;

            private bool _lIsConstructionFinished;

     

            // GetAbstractGenPrivateFields(1)

            [DevExpress.Xpo.KeyAttribute(true)]

            [DevExpress.Xpo.PersistentAttribute("PK")]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(false)]

            [System.ComponentModel.BrowsableAttribute(false)]

            private Guid _guidOid;

     

            // GetAbstractGenPrivateFields(2)

            private Parent _fkParent;

            private string _sText1;

            private string _sText2;

            private string _sText3;

            private string _sText4;

            private string _sText5;

            private string _sText6;

            private string _sMemo1;

            private string _sMemo2;

            private string _sMemo3;

            private string _sMemo4;

            private string _sMemo5;

            private string _sMemo6;

     

            // GetAbstractGenPrivateFields(3)

            private bool _lLocalMemo1;

            private bool _lSavedMemo1;

            private bool _lLocalMemo2;

            private bool _lSavedMemo2;

            private bool _lLocalMemo5;

            private bool _lSavedMemo5;

            private bool _lLocalMemo6;

            private bool _lSavedMemo6;

     

            // GetAbstractGenGettersAndSetters(1)

            [DevExpress.Xpo.SizeAttribute(50)]

            [DevExpress.Xpo.DbTypeAttribute("nchar(50)")]

            [DevExpress.Xpo.PersistentAttribute(Profix.UltraSimple.Database.Child.Properties.Text2)]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(false)]

            private string PrivateText2

            {

                get

                {

                    return this._sText2;

                }

                set

                {

                    if (this._sText2 != value)

                    {

                        string sText2 = this._sText2;

                        this._sText2 = value;

                        this.OnChanged(Profix.UltraSimple.Database.Child.Properties.Text2, sText2, this._sText2);

                    }

                }

            }

     

            // GetAbstractGenGettersAndSetters(1)

            [DevExpress.Xpo.SizeAttribute(50)]

            [DevExpress.Xpo.DbTypeAttribute("nchar(50)")]

            [DevExpress.Xpo.PersistentAttribute(Profix.UltraSimple.Database.Child.Properties.Text4)]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(false)]

            [System.ComponentModel.DefaultValueAttribute(Profix.UltraSimple.Database.Child.Defaults.Text4)]

            private string PrivateText4

            {

                get

                {

                    return this._sText4;

                }

                set

                {

                    if (this._sText4 != value)

                    {

                        string sText4 = this._sText4;

                        this._sText4 = value;

                        this.OnChanged(Profix.UltraSimple.Database.Child.Properties.Text4, sText4, this._sText4);

                    }

                }

            }

     

            // GetAbstractGenGettersAndSetters(1)

            [DevExpress.Xpo.SizeAttribute(50)]

            [DevExpress.Xpo.DbTypeAttribute("nchar(50)")]

            [DevExpress.Xpo.PersistentAttribute(Profix.UltraSimple.Database.Child.Properties.Text6)]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(false)]

            private string PrivateText6

            {

                get

                {

                    return this._sText6;

                }

                set

                {

                    if (this._sText6 != value)

                    {

                        string sText6 = this._sText6;

                        this._sText6 = value;

                        this.OnChanged(Profix.UltraSimple.Database.Child.Properties.Text6, sText6, this._sText6);

                    }

                }

            }

     

            // GetAbstractGenGettersAndSetters(1)

            [DevExpress.Xpo.SizeAttribute(DevExpress.Xpo.SizeAttribute.Unlimited)]

            [DevExpress.Xpo.DbTypeAttribute("nvarchar(MAX)")]

            [DevExpress.Xpo.DelayedAttribute()]

            [DevExpress.Xpo.PersistentAttribute(Profix.UltraSimple.Database.Child.Properties.Memo2)]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(false)]

            private string PrivateMemo2

            {

                get

                {

                    if (this._lLocalMemo2)

                        return this._sMemo2;

                    this._sMemo2 = this.GetDelayedPropertyValue<string>("PrivateMemo2");

                    this._lLocalMemo2 = true;

                    this._lSavedMemo2 = true;

                    return this._sMemo2;

                }

                set

                {

                    if ((this._lLocalMemo2 == false) || (this._lSavedMemo2 == false) || (this._sMemo2 != value))

                    {

                        bool lDoSave = (this._lSavedMemo2 == false) || (this._sMemo2 != value);

                        this._sMemo2 = value;

                        this._lLocalMemo2 = true;

                        if (lDoSave)

                        {

                            this._lSavedMemo2 = true;

                            this.SetDelayedPropertyValue<string>("PrivateMemo2", value);

                        }

                    }

                }

            }

     

            // GetAbstractGenGettersAndSetters(1)

            [DevExpress.Xpo.SizeAttribute(DevExpress.Xpo.SizeAttribute.Unlimited)]

            [DevExpress.Xpo.DbTypeAttribute("nvarchar(MAX)")]

            [DevExpress.Xpo.PersistentAttribute(Profix.UltraSimple.Database.Child.Properties.Memo4)]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(false)]

            private string PrivateMemo4

            {

                get

                {

                    return this._sMemo4;

                }

                set

                {

                    if (this._sMemo4 != value)

                    {

                        string sMemo4 = this._sMemo4;

                        this._sMemo4 = value;

                        this.OnChanged(Profix.UltraSimple.Database.Child.Properties.Memo4, sMemo4, this._sMemo4);

                    }

                }

            }

     

            // GetAbstractGenGettersAndSetters(1)

            [DevExpress.Xpo.SizeAttribute(DevExpress.Xpo.SizeAttribute.Unlimited)]

            [DevExpress.Xpo.DbTypeAttribute("nvarchar(MAX)")]

            [DevExpress.Xpo.DelayedAttribute()]

            [DevExpress.Xpo.PersistentAttribute(Profix.UltraSimple.Database.Child.Properties.Memo6)]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(false)]

            [System.ComponentModel.DefaultValueAttribute(Profix.UltraSimple.Database.Child.Defaults.Memo6)]

            private string PrivateMemo6

            {

                get

                {

                    if (this._lLocalMemo6)

                        return this._sMemo6;

                    if (this.IsNew)

                    {

                        this._sMemo6 = Profix.UltraSimple.Database.Child.Defaults.Memo6;

                        this._lSavedMemo6 = false;

                    }

                    else

                    {

                        this._sMemo6 = this.GetDelayedPropertyValue<string>("PrivateMemo6");

                        this._lSavedMemo6 = true;

                    }

                    this._lLocalMemo6 = true;

                    return this._sMemo6;

                }

                set

                {

                    if ((this._lLocalMemo6 == false) || (this._lSavedMemo6 == false) || (this._sMemo6 != value))

                    {

                        bool lDoSave = (this._lSavedMemo6 == false) || (this._sMemo6 != value);

                        this._sMemo6 = value;

                        this._lLocalMemo6 = true;

                        if (lDoSave)

                        {

                            this._lSavedMemo6 = true;

                            this.SetDelayedPropertyValue<string>("PrivateMemo6", value);

                        }

                    }

                }

            }

     

            #endregion // Private

     

            #region Public

     

            // GetAbstractGenConstructor1AllColumnsInclusiveDefaults

            public AChild(

                  DevExpress.Xpo.Session poSession

                , Parent pfkParent

                , string psText1

                , string psText2

                , string psText3

                , string psText4

                , string psText5

                , string psText6

                , string psMemo1

                , string psMemo2

                , string psMemo3

                , string psMemo4

                , string psMemo5

                , string psMemo6)

                : base(poSession)

            {

                if (psText3 == null)

                    throw new ArgumentNullException("psText3", "psText3 == null");

                if (psText4 == null)

                    throw new ArgumentNullException("psText4", "psText4 == null");

                if (psText5 == null)

                    throw new ArgumentNullException("psText5", "psText5 == null");

                if (psText6 == null)

                    throw new ArgumentNullException("psText6", "psText6 == null");

                if (psMemo5 == null)

                    throw new ArgumentNullException("psMemo5", "psMemo5 == null");

                if (psMemo6 == null)

                    throw new ArgumentNullException("psMemo6", "psMemo6 == null");

                this.Parent = pfkParent;

                this.Text1 = psText1;

                this.Text2 = psText2;

                this.Text3 = psText3;

                this.Text4 = psText4;

                this.Text5 = psText5;

                this.Text6 = psText6;

                this.Memo1 = psMemo1;

                this.Memo2 = psMemo2;

                this.Memo3 = psMemo3;

                this.Memo4 = psMemo4;

                this.Memo5 = psMemo5;

                this.Memo6 = psMemo6;

            }

     

            // GetAbstractGenConstructor2AllColumnsExclusiveDefaults

            public AChild(

                  DevExpress.Xpo.Session poSession

                , Parent pfkParent

                , string psText1

                , string psText2

                , string psText5

                , string psText6

                , string psMemo1

                , string psMemo2

                , string psMemo3

                , string psMemo4)

                : base(poSession)

            {

                if (psText5 == null)

                    throw new ArgumentNullException("psText5", "psText5 == null");

                if (psText6 == null)

                    throw new ArgumentNullException("psText6", "psText6 == null");

                this.Parent = pfkParent;

                this.Text1 = psText1;

                this.Text2 = psText2;

                this.Text3 = Profix.UltraSimple.Database.Child.Defaults.Text3;

                this.Text4 = Profix.UltraSimple.Database.Child.Defaults.Text4;

                this.Text5 = psText5;

                this.Text6 = psText6;

                this.Memo1 = psMemo1;

                this.Memo2 = psMemo2;

                this.Memo3 = psMemo3;

                this.Memo4 = psMemo4;

            }

     

            // GetAbstractGenConstructor3NonNullableColumnsInclusiveDefaults

            public AChild(

                  DevExpress.Xpo.Session poSession

                , string psText3

                , string psText4

                , string psText5

                , string psText6

                , string psMemo5

                , string psMemo6)

                : base(poSession)

            {

                if (psText3 == null)

                    throw new ArgumentNullException("psText3", "psText3 == null");

                if (psText4 == null)

                    throw new ArgumentNullException("psText4", "psText4 == null");

                if (psText5 == null)

                    throw new ArgumentNullException("psText5", "psText5 == null");

                if (psText6 == null)

                    throw new ArgumentNullException("psText6", "psText6 == null");

                if (psMemo5 == null)

                    throw new ArgumentNullException("psMemo5", "psMemo5 == null");

                if (psMemo6 == null)

                    throw new ArgumentNullException("psMemo6", "psMemo6 == null");

                this.Text3 = psText3;

                this.Text4 = psText4;

                this.Text5 = psText5;

                this.Text6 = psText6;

                this.Memo5 = psMemo5;

                this.Memo6 = psMemo6;

            }

     

            // GetAbstractGenConstructor4NonNullableColumnsExclusiveDefaults

            public AChild(

                  DevExpress.Xpo.Session poSession

                , string psText5

                , string psText6)

                : base(poSession)

            {

                if (psText5 == null)

                    throw new ArgumentNullException("psText5", "psText5 == null");

                if (psText6 == null)

                    throw new ArgumentNullException("psText6", "psText6 == null");

                this.Text3 = Profix.UltraSimple.Database.Child.Defaults.Text3;

                this.Text4 = Profix.UltraSimple.Database.Child.Defaults.Text4;

                this.Text5 = psText5;

                this.Text6 = psText6;

            }

     

            // GetAbstractGenConstructor5OnlyTheSessionParameter

            public AChild(DevExpress.Xpo.Session poSession)

                : base(poSession)

            {

            }

     

            // GetAbstractGenPublicGetOid

            [DevExpress.Xpo.PersistentAliasAttribute("_guidOid")]

            [System.ComponentModel.BrowsableAttribute(false)]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(true)]

            public Guid Oid

            {

                get

                {

                    if (this.IsNew && this.IsConstructionFinished && (this._guidOid == Guid.Empty))

                        this._guidOid = DevExpress.Xpo.XpoDefault.NewGuid();

                    return this._guidOid;

                }

            }

     

            // GetAbstractGenGettersAndSetters(1)

            [DevExpress.Xpo.SizeAttribute(50)]

            [DevExpress.Xpo.DbTypeAttribute("nchar(50)")]

            [DevExpress.Xpo.PersistentAttribute(Profix.UltraSimple.Database.Child.Properties.Text1)]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(true)]

            public string Text1

            {

                get

                {

                    return this._sText1;

                }

                set

                {

                    if (this._sText1 != value)

                    {

                        string sText1 = this._sText1;

                        this._sText1 = value;

                        this.OnChanged(Profix.UltraSimple.Database.Child.Properties.Text1, sText1, this._sText1);

                    }

                }

            }

     

            // GetAbstractGenGettersAndSetters(2)

            [DevExpress.Xpo.SizeAttribute(50)]

            [DevExpress.Xpo.DbTypeAttribute("nchar(50)")]

            [DevExpress.Xpo.PersistentAliasAttribute("PrivateText2")]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(false)]

            public virtual string Text2

            {

                get

                {

                    return this.PrivateText2;

                }

                set

                {

                    this.PrivateText2 = value;

                }

            }

     

            // GetAbstractGenGettersAndSetters(1)

            [DevExpress.Xpo.SizeAttribute(50)]

            [DevExpress.Xpo.DbTypeAttribute("nchar(50)")]

            [DevExpress.Xpo.PersistentAttribute(Profix.UltraSimple.Database.Child.Properties.Text3)]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(true)]

            [System.ComponentModel.DefaultValueAttribute(Profix.UltraSimple.Database.Child.Defaults.Text3)]

            public string Text3

            {

                get

                {

                    return this._sText3;

                }

                set

                {

                    if (this._sText3 != value)

                    {

                        string sText3 = this._sText3;

                        this._sText3 = value;

                        this.OnChanged(Profix.UltraSimple.Database.Child.Properties.Text3, sText3, this._sText3);

                    }

                }

            }

     

            // GetAbstractGenGettersAndSetters(2)

            [DevExpress.Xpo.SizeAttribute(50)]

            [DevExpress.Xpo.DbTypeAttribute("nchar(50)")]

            [DevExpress.Xpo.PersistentAliasAttribute("PrivateText4")]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(false)]

            [System.ComponentModel.DefaultValueAttribute(Profix.UltraSimple.Database.Child.Defaults.Text4)]

            public virtual string Text4

            {

                get

                {

                    return this.PrivateText4;

                }

                set

                {

                    this.PrivateText4 = value;

                }

            }

     

            // GetAbstractGenGettersAndSetters(1)

            [DevExpress.Xpo.SizeAttribute(50)]

            [DevExpress.Xpo.DbTypeAttribute("nchar(50)")]

            [DevExpress.Xpo.PersistentAttribute(Profix.UltraSimple.Database.Child.Properties.Text5)]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(true)]

            public string Text5

            {

                get

                {

                    return this._sText5;

                }

                set

                {

                    if (this._sText5 != value)

                    {

                        string sText5 = this._sText5;

                        this._sText5 = value;

                        this.OnChanged(Profix.UltraSimple.Database.Child.Properties.Text5, sText5, this._sText5);

                    }

                }

            }

     

            // GetAbstractGenGettersAndSetters(2)

            [DevExpress.Xpo.SizeAttribute(50)]

            [DevExpress.Xpo.DbTypeAttribute("nchar(50)")]

            [DevExpress.Xpo.PersistentAliasAttribute("PrivateText6")]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(false)]

            public virtual string Text6

            {

                get

                {

                    return this.PrivateText6;

                }

                set

                {

                    this.PrivateText6 = value;

                }

            }

     

            // GetAbstractGenGettersAndSetters(1)

            [DevExpress.Xpo.SizeAttribute(DevExpress.Xpo.SizeAttribute.Unlimited)]

            [DevExpress.Xpo.DbTypeAttribute("nvarchar(MAX)")]

            [DevExpress.Xpo.DelayedAttribute()]

            [DevExpress.Xpo.PersistentAttribute(Profix.UltraSimple.Database.Child.Properties.Memo1)]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(true)]

            public string Memo1

            {

                get

                {

                    if (this._lLocalMemo1)

                        return this._sMemo1;

                    this._sMemo1 = this.GetDelayedPropertyValue<string>("Memo1");

                    this._lLocalMemo1 = true;

                    this._lSavedMemo1 = true;

                    return this._sMemo1;

                }

                set

                {

                    if ((this._lLocalMemo1 == false) || (this._lSavedMemo1 == false) || (this._sMemo1 != value))

                    {

                        bool lDoSave = (this._lSavedMemo1 == false) || (this._sMemo1 != value);

                        this._sMemo1 = value;

                        this._lLocalMemo1 = true;

                        if (lDoSave)

                        {

                            this._lSavedMemo1 = true;

                            this.SetDelayedPropertyValue<string>("Memo1", value);

                        }

                    }

                }

            }

     

            // GetAbstractGenGettersAndSetters(2)

            [DevExpress.Xpo.SizeAttribute(DevExpress.Xpo.SizeAttribute.Unlimited)]

            [DevExpress.Xpo.DbTypeAttribute("nvarchar(MAX)")]

            [DevExpress.Xpo.DelayedAttribute()]

            [DevExpress.Xpo.PersistentAliasAttribute("PrivateMemo2")]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(false)]

            public virtual string Memo2

            {

                get

                {

                    return this.PrivateMemo2;

                }

                set

                {

                    this.PrivateMemo2 = value;

                }

            }

     

            // GetAbstractGenGettersAndSetters(1)

            [DevExpress.Xpo.SizeAttribute(DevExpress.Xpo.SizeAttribute.Unlimited)]

            [DevExpress.Xpo.DbTypeAttribute("nvarchar(MAX)")]

            [DevExpress.Xpo.PersistentAttribute(Profix.UltraSimple.Database.Child.Properties.Memo3)]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(true)]

            public string Memo3

            {

                get

                {

                    return this._sMemo3;

                }

                set

                {

                    if (this._sMemo3 != value)

                    {

                        string sMemo3 = this._sMemo3;

                        this._sMemo3 = value;

                        this.OnChanged(Profix.UltraSimple.Database.Child.Properties.Memo3, sMemo3, this._sMemo3);

                    }

                }

            }

     

            // GetAbstractGenGettersAndSetters(2)

            [DevExpress.Xpo.SizeAttribute(DevExpress.Xpo.SizeAttribute.Unlimited)]

            [DevExpress.Xpo.DbTypeAttribute("nvarchar(MAX)")]

            [DevExpress.Xpo.PersistentAliasAttribute("PrivateMemo4")]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(false)]

            public virtual string Memo4

            {

                get

                {

                    return this.PrivateMemo4;

                }

                set

                {

                    this.PrivateMemo4 = value;

                }

            }

     

            // GetAbstractGenGettersAndSetters(1)

            [DevExpress.Xpo.SizeAttribute(DevExpress.Xpo.SizeAttribute.Unlimited)]

            [DevExpress.Xpo.DbTypeAttribute("nvarchar(MAX)")]

            [DevExpress.Xpo.DelayedAttribute()]

            [DevExpress.Xpo.PersistentAttribute(Profix.UltraSimple.Database.Child.Properties.Memo5)]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(true)]

            [System.ComponentModel.DefaultValueAttribute(Profix.UltraSimple.Database.Child.Defaults.Memo5)]

            public string Memo5

            {

                get

                {

                    if (this._lLocalMemo5)

                        return this._sMemo5;

                    if (this.IsNew)

                    {

                        this._sMemo5 = Profix.UltraSimple.Database.Child.Defaults.Memo5;

                        this._lSavedMemo5 = false;

                    }

                    else

                    {

                        this._sMemo5 = this.GetDelayedPropertyValue<string>("Memo5");

                        this._lSavedMemo5 = true;

                    }

                    this._lLocalMemo5 = true;

                    return this._sMemo5;

                }

                set

                {

                    if ((this._lLocalMemo5 == false) || (this._lSavedMemo5 == false) || (this._sMemo5 != value))

                    {

                        bool lDoSave = (this._lSavedMemo5 == false) || (this._sMemo5 != value);

                        this._sMemo5 = value;

                        this._lLocalMemo5 = true;

                        if (lDoSave)

                        {

                            this._lSavedMemo5 = true;

                            this.SetDelayedPropertyValue<string>("Memo5", value);

                        }

                    }

                }

            }

     

            // GetAbstractGenGettersAndSetters(2)

            [DevExpress.Xpo.SizeAttribute(DevExpress.Xpo.SizeAttribute.Unlimited)]

            [DevExpress.Xpo.DbTypeAttribute("nvarchar(MAX)")]

            [DevExpress.Xpo.DelayedAttribute()]

            [DevExpress.Xpo.PersistentAliasAttribute("PrivateMemo6")]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(false)]

            [System.ComponentModel.DefaultValueAttribute(Profix.UltraSimple.Database.Child.Defaults.Memo6)]

            public virtual string Memo6

            {

                get

                {

                    return this.PrivateMemo6;

                }

                set

                {

                    this.PrivateMemo6 = value;

                }

            }

     

            // GetAbstractGenAssociation0NsGetSetMember

            [DevExpress.Xpo.PersistentAttribute(Profix.UltraSimple.Database.Child.ForeignKeys.Parent)]

            [DevExpress.Xpo.AssociationAttribute(Profix.UltraSimple.Database.Parent.Associations.ChildListByParent, typeof(Profix.UltraSimple.Database.AParent))]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(true)]

            public Parent Parent

            {

                get

                {

                    return this._fkParent;

                }

                set

                {

                    if (this._fkParent != value)

                    {

                        Parent fkParent = this._fkParent;

                        this._fkParent = value;

                        this.OnChanged(Profix.UltraSimple.Database.Child.Properties.Parent, fkParent, this._fkParent);

                    }

                }

            }

     

            public override void AfterConstruction()

            {

                base.AfterConstruction();

                this._lIsConstructionFinished = true;

            }

     

            [DevExpress.Xpo.NonPersistentAttribute()]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(false)]

            public bool IsNew

            {

                get

                {

                    if (this._nIsNew == 0)

                        this._nIsNew = base.Session.IsNewObject(this) ? 2 : 1;

                    return this._nIsNew == 2;

                }

            }

     

            [DevExpress.Xpo.NonPersistentAttribute()]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(false)]

            public bool IsConstructionFinished

            {

                get

                {

                    return this._lIsConstructionFinished;

                }

            }

     

            #endregion // Public

        }

    }

     

    using System;

     

    // === ============================================================ ===

    // === Generator: GetImplementationGen                              ===

    // === GenDate  : 7/3/2009 4:14:14 PM                               ===

    // === Version  : 0.0.0.4(Beta)                                     ===

    // === ============================================================ ===

     

    namespace Profix.UltraSimple.Database

    {

        [DevExpress.Xpo.MapInheritanceAttribute(DevExpress.Xpo.MapInheritanceType.ParentTable)]

        [DevExpress.Xpo.DeferredDeletionAttribute(true)]

        [DevExpress.Xpo.OptimisticLockingAttribute(true)]

        [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(true)]

        public partial class Child : AChild

        {

            #region Protected

     

            #endregion // Protected

     

            #region Internal

     

            #endregion // Internal

     

            #region Private

     

            #endregion // Private

     

            #region Public

     

            // GetImplementationGenPublicStaticClassFields(1)

            public static DevExpress.Xpo.PersistentBase.FieldsClass BaseFields

            {

                get { return DevExpress.Xpo.PersistentBase.Fields; }

            }

     

            // GetImplementationGenPublicStaticClassFields(2)

            public new static class Fields

            {

                public static DevExpress.Data.Filtering.OperandProperty Parent { get { return new DevExpress.Data.Filtering.OperandProperty(Profix.UltraSimple.Database.Child.Properties.Parent); } }

                public static DevExpress.Data.Filtering.OperandProperty Text1 { get { return new DevExpress.Data.Filtering.OperandProperty(Profix.UltraSimple.Database.Child.Properties.Text1); } }

                public static DevExpress.Data.Filtering.OperandProperty Text2 { get { return new DevExpress.Data.Filtering.OperandProperty(Profix.UltraSimple.Database.Child.Properties.Text2); } }

                public static DevExpress.Data.Filtering.OperandProperty Text3 { get { return new DevExpress.Data.Filtering.OperandProperty(Profix.UltraSimple.Database.Child.Properties.Text3); } }

                public static DevExpress.Data.Filtering.OperandProperty Text4 { get { return new DevExpress.Data.Filtering.OperandProperty(Profix.UltraSimple.Database.Child.Properties.Text4); } }

                public static DevExpress.Data.Filtering.OperandProperty Text5 { get { return new DevExpress.Data.Filtering.OperandProperty(Profix.UltraSimple.Database.Child.Properties.Text5); } }

                public static DevExpress.Data.Filtering.OperandProperty Text6 { get { return new DevExpress.Data.Filtering.OperandProperty(Profix.UltraSimple.Database.Child.Properties.Text6); } }

                public static DevExpress.Data.Filtering.OperandProperty Memo1 { get { return new DevExpress.Data.Filtering.OperandProperty(Profix.UltraSimple.Database.Child.Properties.Memo1); } }

                public static DevExpress.Data.Filtering.OperandProperty Memo2 { get { return new DevExpress.Data.Filtering.OperandProperty(Profix.UltraSimple.Database.Child.Properties.Memo2); } }

                public static DevExpress.Data.Filtering.OperandProperty Memo3 { get { return new DevExpress.Data.Filtering.OperandProperty(Profix.UltraSimple.Database.Child.Properties.Memo3); } }

                public static DevExpress.Data.Filtering.OperandProperty Memo4 { get { return new DevExpress.Data.Filtering.OperandProperty(Profix.UltraSimple.Database.Child.Properties.Memo4); } }

                public static DevExpress.Data.Filtering.OperandProperty Memo5 { get { return new DevExpress.Data.Filtering.OperandProperty(Profix.UltraSimple.Database.Child.Properties.Memo5); } }

                public static DevExpress.Data.Filtering.OperandProperty Memo6 { get { return new DevExpress.Data.Filtering.OperandProperty(Profix.UltraSimple.Database.Child.Properties.Memo6); } }

            }

     

            // GetImplementationGenPublicStaticClassForeignKeys

            public static class ForeignKeys

            {

                public const string Parent = "FK_Parent";

            }

     

            // GetImplementationGenPublicStaticClassProperties

            public static class Properties

            {

                public const string Parent = "Parent";

                public const string Text1 = "Text1";

                public const string Text2 = "Text2";

                public const string Text3 = "Text3";

                public const string Text4 = "Text4";

                public const string Text5 = "Text5";

                public const string Text6 = "Text6";

                public const string Memo1 = "Memo1";

                public const string Memo2 = "Memo2";

                public const string Memo3 = "Memo3";

                public const string Memo4 = "Memo4";

                public const string Memo5 = "Memo5";

                public const string Memo6 = "Memo6";

            }

     

            // GetImplementationGenPublicStaticClassDefaultValues

            public static class Defaults

            {

                public const string Text3 = "Default value for Text3";

                public const string Text4 = "Default value for Text4";

                public const string Memo5 = "Default value for the Memo5 column";

                public const string Memo6 = "Default value for the Memo6 column";

            }

     

            // GetImplementationGenConstructor1AllColumnsInclusiveDefaults

            public Child(

                  DevExpress.Xpo.Session poSession

                , Parent pfkParent

                , string psText1

                , string psText2

                , string psText3

                , string psText4

                , string psText5

                , string psText6

                , string psMemo1

                , string psMemo2

                , string psMemo3

                , string psMemo4

                , string psMemo5

                , string psMemo6)

                : base(poSession, pfkParent, psText1, psText2, psText3, psText4, psText5, psText6, psMemo1, psMemo2, psMemo3, psMemo4, psMemo5, psMemo6)

            {

            }

     

            // GetImplementationGenConstructor2AllColumnsExclusiveDefaults

            public Child(

                  DevExpress.Xpo.Session poSession

                , Parent pfkParent

                , string psText1

                , string psText2

                , string psText5

                , string psText6

                , string psMemo1

                , string psMemo2

                , string psMemo3

                , string psMemo4)

                : base(poSession, pfkParent, psText1, psText2, psText5, psText6, psMemo1, psMemo2, psMemo3, psMemo4)

            {

            }

     

            // GetImplementationGenConstructor3NonNullableColumnsInclusiveDefaults

            public Child(

                  DevExpress.Xpo.Session poSession

                , string psText3

                , string psText4

                , string psText5

                , string psText6

                , string psMemo5

                , string psMemo6)

                : base(poSession, psText3, psText4, psText5, psText6, psMemo5, psMemo6)

            {

            }

     

            // GetImplementationGenConstructor4NonNullableColumnsExclusiveDefaults

            public Child(

                  DevExpress.Xpo.Session poSession

                , string psText5

                , string psText6)

                : base(poSession, psText5, psText6)

            {

            }

     

            // GetImplementationGenConstructor6ObsoleteNoSessionParameter

            [System.ObsoleteAttribute("Constructor only to be used for deserialization", true)]

            public Child()

                : base(Profix.ProfixSession.DefaultSession)

            {

            }

     

            // GetImplementationGenConstructor7ObsoleteOnlyTheSessionParameter

            [System.ObsoleteAttribute("Constructor only to be used for deserialization", true)]

            public Child(DevExpress.Xpo.Session poSession)

                : base(poSession)

            {

            }

     

            #endregion // Public

        }

    }

     

    using System;

     

    // === ============================================================ ===

    // === Generator: GetImplementationImp                              ===

    // === GenDate  : 7/2/2009 3:19:00 PM                               ===

    // === Version  : 0.0.0.4(Beta)                                     ===

    // === ============================================================ ===

     

    namespace Profix.UltraSimple.All.Database

    {

        public partial class Child

        {

            #region Protected

     

            #endregion // Protected

     

            #region Internal

     

            #endregion // Internal

     

            #region Private

     

            #endregion // Private

     

            #region Public

     

            #endregion // Public

        }

    }

     

  • Tolis Bekiaris [DX-Squad]

    Re: Problem with 0/1-N relations defined in a abstract class.

    7/3/2009 10:56 AM
    • Top 50 Contributor
    • Joined on 6/21/2007
    • Posts 592

    You can not add associations at abstract classes

  • Frans de Wit

    Re: Problem with 0/1-N relations defined in a abstract class.

    7/3/2009 2:08 PM
    • Not Ranked
    • Joined on 6/19/2009
    • Posts 18

    Tolis,

    No it has nothing to do with the fact that the base class is abstract, if I make it non-abstract then the same problem exists. Any way, if that was the solution to the problem, then I would be happy to make the base class non abstract, even if that is less ‘pure’ J

    Regards,

    Frans.

  • Tolis Bekiaris [DX-Squad]

    Re: Problem with 0/1-N relations defined in a abstract class.

    7/3/2009 2:16 PM
    • Top 50 Contributor
    • Joined on 6/21/2007
    • Posts 592

    it is better when you have so much to attach a sample project so we can help you easily

  • Frans de Wit

    Re: Problem with 0/1-N relations defined in a abstract class.

    7/3/2009 3:38 PM
    • Not Ranked
    • Joined on 6/19/2009
    • Posts 18

     Tolis,

    Thanks for giving this so much attention, attached you will find a zipped VS project.

    Regards,

    Frans.

  • Tolis Bekiaris [DX-Squad]

    Re: Problem with 0/1-N relations defined in a abstract class.

    7/3/2009 5:59 PM
    • Top 50 Contributor
    • Joined on 6/21/2007
    • Posts 592

    Frans

    from what I see yes the problem is that you declare associations at abstract classes. I  have modified your source in order to make the test pass. Search for "by tolis"

    Also I do not know if you have seen this one.

    CodeSmith templates for Xaf

    modified sources

  • Frans de Wit

    Re: Problem with 0/1-N relations defined in a abstract class.

    7/4/2009 4:29 AM
    • Not Ranked
    • Joined on 6/19/2009
    • Posts 18

    Tolis,

    Thanks for having a look, and moving the association to the sub-class makes it work. The problem is, this solves not my problem. The code has been created by a code generator, by using a database as the template. The idea is to generate a class (the base class) and then let the user/programmer change the behavior of the class by overriding the base class. This should be done by modifying the source files in the 'Implementation' folder.

    The code generator can/should be run if the database is changed. The generator then will create new sources in the ‘Generated’ folder and leave all source files in the ‘Implemented’ folder unchanged. This way one is free to change the database without affecting the user/programmer created code. In this scenario all generated code must reside in the ‘Generated’ directory, any code pushed to the ‘Implementation’ directory could render the code generator useless (any way less practical).

    When de association is moved to the sub class, then it is no longer possible to override the association properties and this is a big problem, the mechanism is exposed to the user/programmer and the class behavior is no longer override-able. The properties 'Child.Patrent' and 'Parent.ChildList' must be implemented in the base class.

    Instead of moving the association properties to the sub class, I could remove the abstractness of the base class, but when I do that:

    Change: From: public abstract class AChild : Profix.AProfixXPCustomObject, Profix.IProfixXPCustomObject

    To: public class AChild : Profix.AProfixXPCustomObject, Profix.IProfixXPCustomObject

    And: From: public abstract class AParent : Profix.AProfixXPCustomObject, Profix.IProfixXPCustomObject

    To: public class AParent : Profix.AProfixXPCustomObject, Profix.IProfixXPCustomObject

    The error remains:

    failed: DevExpress.Xpo.Exceptions.AssociationInvalidException : There is a malformed association 'FK_Child_FK_Parent'. Cannot find the associated member for 'Profix.UltraSimple.Database.AChild.Parent' in the class 'Profix.UltraSimple.Database.Parent'

    at DevExpress.Xpo.Metadata.XPMemberInfo.GetAssociatedMember()

    at DevExpress.Xpo.Metadata.XPMemberInfo.ProcessAssociationRefChange(Session session, Object referenceMemberOwner, Object oldValue, Object newValue, Boolean skipNonLoadedCollections)

    at DevExpress.Xpo.Session.TriggerObjectChanged(Object changedObject, ObjectChangeEventArgs e)

    C:\Work\VS_ProfixXpoTools\ConsoleBasedXpoGenData\UltraSimple\Generated.All\AChild.cs(677,0): at Profix.UltraSimple.Database.AChild.set_Parent(Parent value)

    C:\Work\VS_ProfixXpoTools\ConsoleBasedXpoGenData\UltraSimple\UnitTestUltraSimple.cs(32,0): at Profix.UnitTestsUltraSimple.CreateCTest()

    The problem seems to be, XPO is looking for the 'other' half of the association in the class 'Profix.UltraSimple.Database.Parent' and it should be looking in 'Profix.UltraSimple.Database.AParent'. Changing the base class from abstract to non-abstract is not changing this behavior (of XPO), the questions is thus, how to change this behavior, how to make that XPO will find the 'other' association part in AParent.

    Regards,

    Frans.

  • Tolis Bekiaris [DX-Squad]

    Re: Problem with 0/1-N relations defined in a abstract class.

    7/4/2009 4:47 AM
    • Top 50 Contributor
    • Joined on 6/21/2007
    • Posts 592

    Frans

    in ordernot to have exceptions 

    your AChild should have this code

     

            [DevExpress.Xpo.PersistentAttribute(Profix.UltraSimple.Database.Child.ForeignKeys.Parent)]

            [DevExpress.Xpo.AssociationAttribute(Profix.UltraSimple.Database.Parent.Associations.ChildListByParent, typeof(Profix.UltraSimple.Database.AParent))]

            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(true)]

            public AParent Parent

            {

                get

                {

                    return this._fkParent;

                }

                set

                {

                    if (this._fkParent != value)

                    {

                        AParent fkParent = this._fkParent;

                        this._fkParent = value;

                        this.OnChanged(Profix.UltraSimple.Database.Child.Properties.Parent, fkParent, this._fkParent);

                    }

                }

            }

    and you APArent this
            [DevExpress.Xpo.AssociationAttribute(Profix.UltraSimple.Database.Parent.Associations.ChildListByParent, typeof(Profix.UltraSimple.Database.AChild))]
            [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(true)]
            public DevExpress.Xpo.XPCollection<Profix.UltraSimple.Database.AChild> ChildListByParent
            {
                get
                {
                    DevExpress.Xpo.XPCollection<Profix.UltraSimple.Database.AChild> aoChildListByParent
                        = this.GetCollection<Profix.UltraSimple.Database.AChild>(Profix.UltraSimple.Database.Parent.Properties.ChildListByParent);
                    return aoChildListByParent;
                }
            }
    also have a look at that 
    I would try using inheritance mapping to my class so performance to be improved

     

  • Frans de Wit

    Re: Problem with 0/1-N relations defined in a abstract class.

    7/4/2009 5:38 AM
    • Not Ranked
    • Joined on 6/19/2009
    • Posts 18

    Tolis,

    Thanks again. Inheritance mapping is being used by the classes generated to move the data of the base class and the sub class into one table.

    The class Child looks like:

    [DevExpress.Xpo.MapInheritanceAttribute(DevExpress.Xpo.MapInheritanceType.ParentTable)]

    [DevExpress.Xpo.DeferredDeletionAttribute(true)]

    [DevExpress.Xpo.OptimisticLockingAttribute(true)]

    [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(true)]

    public partial class Child ... { ... }

    And the class AChild looks like:

    [DevExpress.Xpo.PersistentAttribute("Child")]

    [DevExpress.Xpo.MemberDesignTimeVisibilityAttribute(false)]

    public class AChild ... { ... }

    The solution that you give will work but it returns the wrong type's, the property parent (of the class AChild) should return a type of 'Parent' and the collection returned by the property ChilkdListByParent (of the class AParent) should be returning a collection of 'Child's. The classes AChild and AParent (abstract or not) will never be instantiated, they do not contain any useful code, and casting (I do not think that it will work) will not be the solution.

    Regards,

    Frans.

  • Jascha

    Re: Problem with 0/1-N relations defined in a abstract class.

    7/4/2009 9:22 AM
    • Top 50 Contributor
    • Joined on 5/4/2007
    • Posts 935
    Hi Frans / Tolis,
     
    IIRC I think you can add an association to an abstract class but you cannot add one to a non-persistent class - i.e. the class must have a corresponding table to hold the FK. So the class must be declared something like:
     
    [Persistent]
    public abstract class MyClass...
     
    Jascha
    "Tolis Bekiaris" wrote in message news:267616@community.devexpress.com...

    You can not add associations at abstract classes


    Best Regards

    My Blog
    CodeRush plugins for Xaf

    http://community.devexpress.com/forums/p/78196/267616.aspx#267616

  • Frans de Wit

    Re: Problem with 0/1-N relations defined in a abstract class.

    7/6/2009 4:30 PM
    • Not Ranked
    • Joined on 6/19/2009
    • Posts 18

     

    All,

    The problem has been resolved, the selected solution is not the nicest but I have to do with what works J.

    There is a solution attached to the message this shows the solution, just open the solution and search for ‘Fixed’.

    Basically the problem was solved by moving the association assessors to the non-virtual class. The virtual class provide the field and the OnChange() method, and the virtual class contains the meta data. My main problem with this is that the user/programmer cannot override the class behavior. This has been solved by adding virtual ‘<…>BeforeSet(…)’ and ‘…AfterGet(…)’ methods when requested (using meta data in the SQL ERD database).

    One new problem has popped up, but I will open a new thread for that one J

    Regards, and thanks for having a look,

    Frans.

     

     

More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.