Ticket Q472381
Visible to All Users

Why does not the NewObjectViewController use NestedObjectSpace?

created 12 years ago

Hello,

i have written a new controller, that overrides the ObjectCreating Event from the NewObjectViewController, because it does not use Nested ObjectSpace.

The new Event looks like this:

C#
void InsuredPersonTariffSelectionController_ObjectCreating(object sender, ObjectCreatingEventArgs e) { var listView = Frame.GetController<LinkToListViewController>(); var nestedFrame = listView.Frame as NestedFrame; if (nestedFrame == null) return; var detailView = nestedFrame.ViewItem.View; var insuredPerson = detailView.CurrentObject as IInsuredPerson; if (e.ObjectType == typeof(IInsuredPersonTariff) && insuredPerson != null) { e.ObjectSpace = XPObjectSpace.FindObjectSpaceByObject(insuredPerson).CreateNestedObjectSpace(); var insuredPersonTariff = e.ObjectSpace.CreateObject<IInsuredPersonTariff>(); insuredPersonTariff.InsuredPerson = e.ObjectSpace.GetObject(insuredPerson as IInsuredPerson); e.NewObject = insuredPersonTariff; } }

The problem is, if i do not use the new created NestedObjectSpace instead of the old e.ObjectSpace, i cannot get the insuredPerson-Object with the e.ObjectSpace.GetObject-Method.

My workaround works fine, but because of this workaround i have to override a second event, too.
I have to override the CustomProcessSelectedItem-Event from the ListViewProcessCurrentObjectController.

C#
void listViewController_CustomProcessSelectedItem(object sender, CustomProcessListViewSelectedItemEventArgs e) { if (e.InnerArgs.CurrentObject is IInsuredPersonTariff) { var oldObjectSpace = XPObjectSpace.FindObjectSpaceByObject(e.InnerArgs.CurrentObject); var nestedObjectSpace = oldObjectSpace.CreateNestedObjectSpace(); ShowViewParameters showViewParameters = new ShowViewParameters(); showViewParameters.CreatedView = Application.CreateDetailView(nestedObjectSpace, nestedObjectSpace.GetObject(e.InnerArgs.CurrentObject), true); showViewParameters.Context = TemplateContext.View; showViewParameters.TargetWindow = TargetWindow.NewModalWindow; Application.ShowViewStrategy.ShowView(showViewParameters, new ShowViewSource(Frame, null)); e.Handled = true; } }

if i do not override this controller, i get an exception that the selected Item is not saved at the moment and cannot open the DetailView.

My Questions are:
- Why is not used a NestedObjectSpace in the NewObjectViewController instead of the XPObjectSpace?
- Is it possible to use the NestedObjectSpace without the change i used for the ListViewProcessCurrentObjectController?

My used DomainComponents:

C#
[DomainComponent] public interface IInsuredPersonTariff { /// <summary> /// Tarif /// </summary> [ImmediatePostData] [DataSourceProperty("AvailableTariffs")] [DevExpress.Xpo.Delayed] ITariff Tariff { get; set; } /// <summary> /// Verfügbaren Tarife einer Sparten(NonPersistenDc) /// </summary> [NonPersistentDc] [ImmediatePostData] IList<ITariff> AvailableTariffs { get; } /// <summary> /// Beitrag /// </summary> decimal Contribution { get; set; } /// <summary> /// Versicherte Person /// </summary> [ImmediatePostData] IInsuredPerson InsuredPerson { get; set; } } [DomainComponent] public interface IInsuredPerson { IContractBase Contract { get; set; } [BackReferenceProperty("InsuredPerson")] IList<IInsuredPersonTariff> InsuredPersonTariffs { get; } } /// <summary> /// Tarif /// </summary> [DomainComponent] [NavigationItem] [XafDefaultProperty("Name")] public interface ITariff { //Some Propertys... }
Comments (1)
Dennis Garavsky (DevExpress) 12 years ago

    Hello Michael,
    We are working on your issue and will get back to you as soon as we can.

    Answers approved by DevExpress Support

    created 12 years ago (modified 9 years ago)

    Hello Michael,
    When designing XAF many years ago we implemented the following behavior when XPO is used for data access:
     - if an object is aggregated (when this object is a part of a master object), a XPNestedObjectSpace is created for its DetailView, because this object should not be physically saved to the database until its owner is saved itself.
     - if an object is not aggregated (when this object can exist separately), a separate XPObjectSpace is used for its DetailView;
    - a nested ListView where objects from the detail collections are shown uses the same master XPObjectSpace regardless of the aggregation.
    The same behavior is enforced when opening Views for existing objects, and not only for new ones.
    This can be controlled via the virtual GetObjectSpaceToShowViewFrom method of the XafApplication class.
    To learn more about ObjectSpace and Views in XAF, check out the following documentation:
    http://documentation.devexpress.com/#Xaf/clsDevExpressExpressAppBaseObjectSpacetopic
    http://documentation.devexpress.com/#Xaf/CustomDocument2611
    P.S.
    In Entity Framework, there is no such entity as XPNestedObjectSpace or UnitOfWork at all.

      Comments (2)

        Thank You! Aggregated solved my problem… :-)

        Dennis Garavsky (DevExpress) 12 years ago

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.