CSLA .NET

From Rockford Lhotka's Expert C# 2005 and VB 2005 Business Objects books

Welcome to CSLA .NET Sign in | Join | Help
in Search

Use relation between CSLA Business Objects

Last post 05-26-2008, 10:45 PM by juancho559. 6 replies.
Sort Posts: Previous Next
  •  05-18-2008, 11:11 AM 23640

    Use relation between CSLA Business Objects

    Hi,

    I would like to know how is the best way to model an use relation between business objects in CSLA?

    For example: I have a business object called Payment. This object has many properties like PaymentId, OrderId, BillingInfo, ShippingInfo.

    BillingInfo and ShippingInfo are two businness objects storing all the information about the billing and shipping.

    When I retrieve the information about billing and Shipping I store this information in the payment object, for example: 

    Payment.BillingInfo = Billing.GetBillingById(idBilling);
    Payment.ShippingInfo = Shipping.GetShippingById(IdShipping);

    When I try to update the payment object, I receive this exception: "Edit level mismatch in AcceptChanges".

    So, How is the best way to model this scenario or how can I solve this problem?

    I appreciate your help!!

     

     

  •  05-18-2008, 6:33 PM 23641 in reply to 23640

    RE: Use relationship in CSLA Business Objects

    This all looks OK.  This code should not cause edit level mismatch.  Are you calling BeginEdit immediately after loading the object before UI has a chance to interact with it?

     

    Sergey Barskiy

    Senior Consultant

    office: 678.405.0687 | mobile: 404.388.1899

    cid:_2_0648EA840648E85C001BBCB886257279
    Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

     

    From: juancho559 [mailto:cslanet@lhotka.net]
    Sent: Sunday, May 18, 2008 12:12 PM
    To: Sergey Barskiy
    Subject: [CSLA .NET] Use relationship in CSLA Business Objects

     

    Hi,

    I would like to know how is the best way to model an use relationship between business objects in CSLA?

    For example: I have a business object called Payment. This object has many properties like PaymentId, OrderId, BillingInfo, ShippingInfo.

    BillingInfo and ShippingInfo are two businness objects storing all the information about the billing and the shipping.

    I just want to avoid the "Edit level mismatch in AcceptChanges" exception when I reference this objects. I get this exception when I do this and try to update the payment object:

    Payment.BillingInfo = Billing.GetBillingById(idBilling);
    Payment.ShippingInfo = Shipping.GetShippingById(IdShipping);

    So, How is the best way to model this scenario?

    I appreciate your help!!

     

     



  •  05-18-2008, 10:43 PM 23643 in reply to 23641

    Re: RE: Use relationship in CSLA Business Objects

    Yes, the code is equal to Project Tracker Sample.

    When I load the form, I bind the UI and call the BeginEdit method.

    AddWinPart(new ProjectEdit(Project.GetProject(projectId)));

        public ProjectEdit(Project project)
        {
          InitializeComponent();

          // store object reference
          _project = project;

          // set up binding
          this.roleListBindingSource.DataSource = RoleList.GetList();

          BindUI();

          // check authorization
          ApplyAuthorizationRules();
        }

    regards...

     

  •  05-19-2008, 7:16 AM 23647 in reply to 23643

    RE: RE: Use relationship in CSLA Business Objects

    Ahh, I see…

    I think this is because you are loading child objects through public properties, dirtying the parent object.  Load them through private members instead:

     

    Payment._billingInfo = Billing.GetBillingById(idBilling);
    Payment._shippingInfo = Shipping.GetShippingById(IdShipping);

     

    Sergey Barskiy

    Senior Consultant

    office: 678.405.0687 | mobile: 404.388.1899

    cid:_2_0648EA840648E85C001BBCB886257279
    Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

     

    From: juancho559 [mailto:cslanet@lhotka.net]
    Sent: Sunday, May 18, 2008 11:44 PM
    To: Sergey Barskiy
    Subject: Re: [CSLA .NET] RE: Use relationship in CSLA Business Objects

     

    Yes, the code is equal to Project Tracker Sample.

    When I load the form, I bind the UI and call the BeginEdit method.

    AddWinPart(new ProjectEdit(Project.GetProject(projectId)));

        public ProjectEdit(Project project)
        {
          InitializeComponent();

          // store object reference
          _project = project;

          // set up binding
          this.roleListBindingSource.DataSource = RoleList.GetList();

          BindUI();

          // check authorization
          ApplyAuthorizationRules();
        }

    regards...

     



  •  05-25-2008, 12:33 AM 23779 in reply to 23647

    Re: RE: RE: Use relationship in CSLA Business Objects

    Hi, Thanks for your response.

    I made the test and I still have the same error. I just change the access modifier to the variables that I want to get.

    internal BillingInfo _billingInfo = null;
    internal ShippingInfo _shippingInfo = null;

    Then, I load the objects from other form.

    Payment._billingInfo = Billing.GetBillingById(idBilling);
    Payment._shippingInfo = Shipping.GetShippingById(IdShipping);

    Regards...

  •  05-26-2008, 3:14 PM 23786 in reply to 23779

    Re: RE: RE: Use relationship in CSLA Business Objects

    Hi!

    You say "Then, I load the objects from other form."
    But the code you then quote does a standard call to the factory methods...

    If you really get your data from another form, then make sure the data is properly unbound from any controls (most likely a bindingsource control) on that form, leaving  it on edit level 0.

    Stefan

  •  05-26-2008, 10:45 PM 23794 in reply to 23786

    Re: RE: RE: Use relationship in CSLA Business Objects

    Hi Stefan,

    I think that I already know what is the problem. I was retrieving the object to edit from the binding source, and I didn't call the EndEdit in the current object. I just change my code like this:

    //Retrieve current object from the binding source
    System.ComponentModel.IEditableObject current =
    paymentBindingSource.Current
    as System.ComponentModel.IEditableObject;

    //Call EndEdit()
    current.EndEdit();

    _payment = (
    Payment) current;

    Thanks...

View as RSS news feed in XML

Please contact Magenic for your .NET consulting and CSLA .NET mentoring needs.
Please consider making a donation to help support the ongoing development of CSLA .NET.

Make donation through PayPal - it's fast, free and secure!
Why donate?
Powered by Community Server, by Telligent Systems