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!!
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
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!!
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...
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
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...
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;Then, I load the objects from other form.
Payment._billingInfo = Billing.GetBillingById(idBilling);
Payment._shippingInfo = Shipping.GetShippingById(IdShipping);
Regards...
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 sourceThanks...
Copyright (c) Marimer LLC