Current filter:
                                You should refresh the page.
                                  • Hello

                                    I'm consuming a oData service which inherits your XpoDataServiceV3, for Domain Components.
                                    For retrieving data, it is doing good. But for updates, I noticed that the objectSpace parameter is null within the OnSaving() event.
                                    And I need the objectSpace to enforce some logic on the entities.

                                    This is how I initialize the service:
                                    ----------------------------------
                                    static IDataLayer CreateDataLayer()
                                    {
                                    XpoTypesInfoHelper.ForceInitialize();
                                    var typesInfo = XpoTypesInfoHelper.GetTypesInfo();
                                    var xpoTypeInfoSource = XpoTypesInfoHelper.GetXpoTypeInfoSource();
                                    Type type = null;
                                    type = typeof(Survey); typesInfo.RegisterEntity(type.Name, type);
                                    typesInfo.GenerateEntities();

                                    var connectionString = "Pooling=true;Data Source=.;User Id=***;Password=*****;Initial Catalog=****";
                                    var dataStoreProvider = new ConnectionStringDataStoreProvider(connectionString);
                                    var objectSpaceProvider = new XPObjectSpaceProvider(dataStoreProvider, typesInfo, xpoTypeInfoSource);
                                    var dict = objectSpaceProvider.XPDictionary;
                                    var store = XpoDefault.GetConnectionProvider(connectionString, DevExpress.Xpo.DB.AutoCreateOption.SchemaAlreadyExists);

                                    var dataLayer = new ThreadSafeDataLayer(dict, store);
                                    XpoDefault.DataLayer = dataLayer;
                                    return dataLayer;
                                    }
                                    ----------------------------------

                                    Now, the domain component's event:
                                    ----------------------------------
                                    public void OnSaving(Survey instance, IObjectSpace objectSpace)
                                    {
                                    var space = objectSpace; //<---objectSpace is null
                                    //...
                                    //...
                                    //...
                                    }
                                    ----------------------------------

                                    I've tried to use XpoDefault.Session in the OnSaving() event, but it brings an exception saying that the object belongs to another session.
                                    I've even tried "DevExpress.ExpressApp.Xpo.XPObjectSpace.FindObjectSpaceByObject(instance)", but it also returns null.

                                    Finally, is it possible to retrieve the objectSpace (inside the Domain Component logic), from an object that started in a XpoDataServiceV3?

                                • Dennis (DevExpress) 03.18.2013

                                  Hello Sidney,
                                  As I wrote you earlier in your other ticket, we have not yet tested this particular scenario.
                                  In any event, we will be glad to research your project (please attach it here) and advise what can be done to overcome this behavior. Maybe a tiny change is required in our code to support this.

                                • Sidney DC 03.18.2013

                                  Hello Dennis.
                                  Here is the sample.
                                  The project is a miscelania of Xaf + Dxtreme oData + Dxtreme Multichannel, in this order.
                                  Use the Xaf Winforms to compile the database, as I have tested here.
                                  If you need more info, please advise me.

                                • Sidney DC 03.18.2013

                                  Just to document the steps:
                                  After all is compiled, and the DataService1 is started and the multichannel application is pointing to the DataService1 url, try to add a new Survey object by the DxtremeApplication1.
                                  When you click the button "Save", you will receive the message "HERE! ObjectSpace is null"
                                  Look at "XafObjectSpaceNull.Module.BusinessObjects.Survey" class to see the code.

                                • Dennis (DevExpress) 03.19.2013

                                  Hello Sidney,
                                  Thanks for the sample. I will research it and let you know my results. It will require more time, because as I wrote above this scenario is not currently supported.

                                1 Solution

                                Creation Date Importance Sort by

                                Hello Sidney,
                                The IObjectSpace parameter will not be null in this method only if the object is created by means of the ObjectSpace.
                                For instance, you can use the objectSpaceProvider.CreateObjectSpace method to create a valid ObjectSpace object and then use its CreateObject method to create the actual record.
                                I hope you find this information helpful.
                                UPDATE:
                                Attached is a complete sample project (it requires 12.2.8) that shows how to accomplish this. Refer to my blog for more details on this solution: http://dennisgaravsky.blogspot.com/2013/04/exposing-domain-components-dc-via-odata.html

                                • Sidney DC 03.27.2013

                                  Hi Dennis.
                                  But the DataService handle it automatically. How can I accomplish that when the DataService just receive and save the data by itself, without creating the object space? Is there any override I can use for forcing it?

                                • Dennis (DevExpress) 03.28.2013

                                  Sidney,
                                  I am afraid there is no virtual method you can use at the moment.
                                  Unfortunately, the GetSession method of the XpoDataServiceV3 class is internal:

                                  [C#]
                                  internal UnitOfWork GetSession() { UnitOfWork uow; if (!SessionCache.TryGetValue(this, out uow)) { uow = new UnitOfWork(Context.ObjectLayer); SessionCache.Add(this, uow); } return uow; }

                                  If it was not internal and non-overridable, then you could override it to return the Session got from the XAF's ((XPObjectSpace)ObjectSpaceProvider.CreateObjectSpace()).Session property.
                                  There is however the virtual GetService method, but overriding it requires more work:

                                  [C#]
                                  public virtual object GetService(Type serviceType) { if(serviceType == typeof(IDataServiceMetadataProvider)) return Metadata; if(serviceType == typeof(IDataServiceQueryProvider)) return new XpoQueryProvider(this); if(serviceType == typeof(IDataServiceUpdateProvider2)) return new XpoUpdateProvider(GetSession(), this); if(serviceType == typeof(IDataServiceStreamProvider2)) return new XpoStreamProvider(this.CurrentDataSource); if(serviceType == typeof(IDataServiceActionProvider)) { if(typeWithActions == null) typeWithActions = this; return new XpoActionProvider(GetSession(), this, typeWithActions); } return null; }

                                  I asked our XPO guys to provide a good solution for this: XpoDataServiceV3 - Provide a virtual method to create a custom Session. You will be automatically notified of any changes in this regard.

                                • Dennis (DevExpress) 04.02.2013

                                  Sidney,
                                  I have some good news for you. After the XpoDataServiceV3 - Provide a virtual method to create a custom Session request was kindly implemented by the XPO team, I managed to get your service working with DC components and DXTREME. I will post an updated project as soon as I can.