Current filter:
                                You should refresh the page.
                                  • In the code below I wish "Parent" and "Child" base classes to manage some details about versioned objects (not shown in the simplified example). Specialized sub-classes would derive from these base classes and implement the properties specific to them similar to "SpecializedParent" and "SpecializedChild" below.
                                    I would like to have the base classes manage needed Associations but I get the following error when testing the code below.
                                    DevExpress.Xpo.Exceptions.PropertyMissingException: The 'Reference to the 'XpoTestCases.Generics.Parent`1<XpoTestCases.Generics.SpecializedChild>' type' property doesn't exist within the 'XpoTestCases.Generics.SpecializedChild type'
                                    I can eliminate this problem by moving the associations into the Specialized sub-classes (see the attached ZIP for full source for the working case and the non-working case).
                                    Is there anyway to use an Association for a Generic type?
                                    Thanks,
                                    Rich
                                    Excerpt from XpoAssociationWithGenerics.cs in attched ZIP:

                                    [C#]
                                    [NonPersistent] class Parent<T> : XPObject where T : XPObject { public Parent() { } public Parent(Session session) : base(session) { } public string Name; [Association("Parent-Child")] public XPCollection<T> Children { get { return GetCollection<T>("Children"); } } } [NonPersistent] class Child<T> : XPObject { public Child() { } public Child(Session session) : base(session) { } public string Name; [Association("Parent-Child")] public T Parent; } class SpecializedParent : Parent<SpecializedChild> { public SpecializedParent() { } public SpecializedParent(Session session) : base(session) { } public string Specialty; } class SpecializedChild : Child<SpecializedParent> { public SpecializedChild() { } public SpecializedChild(Session session) : base(session) { } public string Specialty; }

                                    -----------------
                                    We do understand your task. We can implement such a feature for some simple situations. However, it won't be possible to determine the exact pair of properties which define an association in a complex situation. Unfortunately, there is no general solution for your task.
                                    In your case, the easiest approach is to explicitly define associations in descendant classes.
                                    Thank you,
                                    Nick
                                    --------
                                    ====
                                    Thanks for the answer.
                                    Although your distinction between "simple" and "complex" "situations" isn't clear to me, I'd assume my example is a "simple situation" one and would qualify for a general solution.
                                    IMO, it would be nice to have some general solution to this problem even if you could only apply it to "simple situations".
                                    In my case, managing the details of the Association is something I would like to completely encapsulate in the base class.
                                    Since I can't do that, my code maintenance and complexity increases.
                                    Currently, in order to make sure the descendants are implementing the required Association properties, I use a generic interface constraint. This allows for catching an omission of the required Association properties at compile time, but there is no compile time check for a missing [Association] attribute (* note: an interface constraint is used because an abstract property has the same problem as a regular property).
                                    An even better solution to my problem would be to add support versioned objects in XPO :)
                                    Thanks,
                                    Rich

                                0 Solutions

                                Creation Date Importance Sort by