Current filter:
                                You should refresh the page.
                                  • XPO always considers gerenics as abstract class. I cannot write code like this:

                                    [C#]
                                    public class DomainObject1<T> : XPObject { public DomainObject1(Session session) : base(session) { } public T Field1; } public class DomainObject2 : XPObject { public DomainObject2(Session session) : base(session) { } public DomainObject1<string> Ref; }

                                    It throws an exception from Session.UpdateSchema:
                                    DevExpress.Xpo.Exceptions.UnableToFillRefTypeException was unhandled
                                      Message="Could not ensure database schema for the 'Ref' member of the 'Module1.DomainObject2' type. Error: While resolving the real object type, a reference to a nonpersistent 'Module1.DomainObject1`1<System.String>' type found"
                                      Source="DevExpress.Xpo.v7.3"
                                      MemberName="Ref"
                                      ObjectName="Module1.DomainObject2"
                                      StackTrace:
                                           at DevExpress.Xpo.Metadata.XPClassInfo.AddClassToDirectlyRefTypes(IDictionary targetList, XPClassInfo info, String refClassName, String refMemberName)
                                           at DevExpress.Xpo.Metadata.XPClassInfo.GetDirectlyRefTypes()
                                           at DevExpress.Xpo.Metadata.XPClassInfo.FillRefTypes(IDictionary filled)
                                           at DevExpress.Xpo.Metadata.XPDictionary.ExpandTypesToEnsure(XPClassInfo[] inputTypesToEnsure, IDictionary alreadyEnsuredTypes)
                                           at DevExpress.Xpo.SimpleDataLayer.UpdateSchema(Boolean dontCreate, XPClassInfo[] types)
                                           at DevExpress.Xpo.Session.UpdateSchema()

                                1 Solution

                                Creation Date Importance Sort by

                                Workaround
                                Currently, please create a specific type descendant from your generic class:

                                [C#]
                                public class DomainObject1<T> : XPObject { public DomainObject1(Session session) : base(session) { } public T Field1; } public class DomainObjectString : DomainObject1<string>; { public DomainObjectString(Session session) : base(session) { } } public class DomainObject2 : XPObject { public DomainObject2(Session session) : base(session) { } public DomainObjectString Ref; }
                                Show all comments
                                • Sviatlana Gurbanovich 12.27.2007

                                  According to Subject of the issue and please give me the Workaround for
                                      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");
                                              }
                                          }
                                      }
                                      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;
                                      }
                                  It is urgent for me.

                                • Nick (DevExpress Support) 12.27.2007

                                  Anatoly,
                                  Thank you for your comment. Generics aren't currently supported in XPO. It's very difficult for us to implement this feature and, unfortunately, we cannot implement it right now, I apologize. Here is a workaround for your situation:

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

                                  Thanks,
                                  Nick

                                • Petr Zima 06.18.2014

                                  Hello. Is there anything new about generic types support in XPO? Thank you

                                • Dennis (DevExpress) 06.18.2014

                                  @Petr: I am afraid we do not have any news on this.

                                • Petr Zima 06.18.2014

                                  OK. Thanks

                                • Carlitos 11.07.2014

                                  This would be really cool to get implemented. I have to write like 60 nonpersistent screens and a generic would make my life easier in code maintenance. In my particular case, my code looks something like this:
                                     public abstract class FilterObjectBase<T> : INotifyPropertyChanged, IReportObject
                                     {
                                         private List<T> reportResults = new List<T>();
                                         private string filter;
                                         private Type filterType = null;
                                         public FilterObjectBase()
                                         {
                                             SetFilterType(typeof(T));
                                         }
                                         [ValueConverter(typeof(TypeToStringConverter)), ImmediatePostData]
                                         [TypeConverter(typeof(PlainObjectHelper))]
                                         public Type FilterType
                                         {
                                         ��   get { return filterType; }
                                         }
                                         [CriteriaOptions("FilterType")]
                                         [EditorAlias(EditorAliases.CriteriaPropertyEditor)]
                                         public string Filter
                                         {
                                             get { return filter; }
                                             set { filter = value; }
                                         }
                                         public List<T> ReportResults
                                         {
                                             get { return reportResults; }
                                         }
                                         public virtual void Execute()
                                         {
                                             Clear();
                                             reportResults.AddRange(new PlainObjectHelper().FillTheList<T>(GetFilter()));
                                             RaisePropertyChanged("ReportResults");
                                         }
                                         public virtual void Clear()
                                         {
                                             reportResults.Clear();
                                             RaisePropertyChanged("ReportResults");
                                         }
                                         public virtual CriteriaOperator GetFilter()
                                         {
                                             return CriteriaOperator.Parse(Filter);
                                         }
                                         protected void RaisePropertyChanged(string propertyName)
                                         {
                                             if (PropertyChanged != null)
                                             {
                                                 PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
                                             }
                                         }
                                         protected void SetFilterType(Type type)
                                         {
                                             filterType = type;
                                             RaisePropertyChanged("FilterType");
                                         }
                                     }
                                  Do you have any suggestion on how this could be implemented and easily maintained? My guess is to write a T4 template. But maybe there is another better Dx XAF way.
                                  Thanks,
                                  Carlos

                                • Dennis (DevExpress) 11.10.2014

                                  Hi Carlos,

                                  I do not quite understand exactly which maintenance problems you have with the current class and I would kindly ask you to elaborate more on this as well as what solution you are proposing to overcome these difficulties.
                                  I guess that you would create descendants of this base class for each required type you need. If so, this inheritance is already supported, and I remember using something similar in the E1744 example (see SearchObjectBase<T>). If possible, please create a separate ticket in the Support Center for this.

                                • Carlitos 11.10.2014

                                  Hi Dennis,
                                  I had never seen this E1744. Works great! It then made me look in my code and found that my module.cs on the
                                  protected override IEnumerable<Type> GetDeclaredExportedTypes()
                                  I was not filtering for !IsAbstract Classes. This is where the solution would fail giving an error on Generics. So I assumed incorrectly that it was not supported. So I have corrected it. Then I have adjusted all my inheritance in order to avoid XPBaseObject. Working completely with POCOs and List<T>
                                  All is working now.
                                  The difference in E1744 strives on that instead of using an Action to create a DetailView for the SearchObject, I use the navigation control to show DetailView. Another change is that I use the FilterControl to build the Criteria, instead of using a bunch of properties to build it. Screenshot attached.
                                  Anyways, you're the man! Couldn't have done it without your help.
                                  Carlos

                                • Dennis (DevExpress) 11.11.2014

                                  I am glad to hear of your results, Carlos. And you are always welcome!:-)