0

I am trying to create a procedure which return an XPcollection like so:

    public XPCollection<Txn> RetrieveTransactions()
    {
        if (ObjectSpace is DevExpress.ExpressApp.Xpo.XPObjectSpace)
        {
            XPCollection txns = (XPCollection)ObjectSpace.CreateCollection(typeof(Txn));
            if (txns.Count == 0)
            {
            }
            return (XPCollection<Txn>)txns;
        }

    }

but I am getting the error below:

    Error   1   Cannot implicitly convert type 'DevExpress.Xpo.XPCollection' to 'DevExpress.Xpo.XPCollection<FX.Module.BusinessObjects.fxdb.Txn>'
Dennis Garavsky
  • 538
  • 3
  • 18
billiard
  • 1
  • 2
  • 3
    Why you can't do this: `XPCollection txns = (XPCollection)ObjectSpace.CreateCollection(typeof(Txn));`? – nempoBu4 Aug 12 '14 at 06:06

1 Answers1

0

The below example is how i create XPCollections, i hope it can help!

    private XPCollection<Txn> retrieveTransactions;

    public XPCollection<Txn> RetrieveTransactions
    {
        get
        {
            if (ObjectSpace is DevExpress.ExpressApp.Xpo.XPObjectSpace)
            {
                this.retrieveTransactions = new XPCollection<Txn>(Session);
            }

            return this.retrieveTransactions;
        }
    }
Shwabster
  • 479
  • 1
  • 10
  • 27
  • With the above I get two errors 1) The name 'ObjectSpace' does not exist in the current context 2) 'DevExpress.Xpo.Session' is a 'type' but is used like a 'variable' – billiard Aug 13 '14 at 07:18
  • 2
    I have edited the code in the answer above. However, a simpler solution was provided by nempoBu4 in comments. Note that this code is supposed to work from within a ViewController where you have access to the ObjectSpace property. If you are in a different context, use the XafApplication.CreateObjectSpace method to obtain the IObjectSpace instance. If you are in the context of the persistent class, then do not use IObjectSpace at all and access the Session property of the persistent class. – Dennis Garavsky Aug 14 '14 at 06:57