Hi.
I have a win. form (Form2) that is bound to a BusinessBase type object. When Form2 is initially opened, it receives the correct values that I am sending it from another form, Form1. When I close Form2 (form2.close()), I return to Form1 to update some values in order to send them back to Form2. However, Form2 does not reflect the updated values. I stepped through the code and found that on the initial open, DataPortal.Create() runs through every property in the business object and sets them correctly; AddBusinessRules() is also called at this point. But on subsequent calls to DataPortal.Create() i.e. private MyBusinessObject _myBusObj = CrossDockSourceProduct.NewEditableRootParent(); it skips all the getters and setters, as well as AddBusinessRules().
I am new to CSLA and probably missing something very basic. I would appreciate your help. Thanks.
public partial class Form2 : Form
{
private Product _product = Product.NewEditableRootParent();
public Form1()
{
InitializeComponent();
this.form1BindingSource.DataSource = this._product;
}
I think the initialization you are seeing is of the static fields and business rules. That only occurs the first time an object of any given type is created, and the results are cached for use as the application runs.
To initialize property values of an object instance you need to implement a DataPortal_Create method. The data portal will invoke this method after creating the object, allowing you to initialize the object instance as necessary.
Thanks for your response, Rocky.
DataPortal.Create() is invoked when I call private Product _product = Product.NewEditableRootParent();. After this initialization, I open a UI form which displays the values in the object instantiated by DataPortal.Create(). The problem is that upon closing this UI form and reopening it (this time with updated values), the form is still displaying the old values that the original object's properties were initialized with. I would expect that that object would have been released and a new one instantiated with the statement, private Product _product = Product.NewEditableRootParent(); What am I missing?
It sounds like the issue is with your UI code or behaviors then. Perhaps when you close the first UI form, the form is somehow being reused, so it doesn't get initialized again? Perhaps you need to make sure that a new instance of the form is created when you reopen it?
That was my initial inclination, but then I stepped through the code and saw that it was stepping into:
public partial class Form2 : Form
{
private Product _product = Product.NewEditableRootParent();
public Form1()
{
InitializeComponent();
this.form1BindingSource.DataSource = this._product;
}
Thought so, wanted to be sure I understood. Thanks very much.
Copyright (c) Marimer LLC