BusinessBindingSource creates mutliple BOs


Author
Message
George Nentidis
George Nentidis
StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)
Group: Forum Members
Posts: 72, Visits: 251
Hello again.

I don't know if this is actually a problem or not but I though I should ask.

The BusinessBindingSource object seems to create its own instance of the BO to which it is bound to, instead of using the one in the form. It started like this: I drop my BO to the form and connect it to the BusinessBindingSource which I also drop on the form. Then bind some controls to it. By placing breakpoints to the constructors of the BO I have found out that the BusinessBindingSource creates another instance of the BO and modifies that one. This causes the FieldPropertyChanged events of the object that is dropped on the form not to be called, since it is another object that is changing.

I have tried to reproduce this using the BussinesBindingSource that comes with the framework. I have placed a breakpoint in the CustomersBO constructor, and found out that it is called 100 times. One for each row of the query. Is this ok?

If this is ok, (perhaps you're using a shared table) then is there a way I can make the FieldPropertyChanged of the BO that is dropped on the form to be called?

I have attached the BussinesBidingSource project, even though I know you already have it. I have only added a counter in the constructor to count the calls.

Thank you.

Attachments
BusinessBindingSource.rar (83 views, 1.00 MB)
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
I have tried to reproduce this using the BussinesBindingSource that comes with the framework. I have placed a breakpoint in the CustomersBO constructor, and found out that it is called 100 times. One for each row of the query. Is this ok?

Yes, this is OK.  The BBS wraps the instance of the BO that you select.  The IBindingList interface expected a unique instance of an object for each....that is why you saw the contructor fire 100 times.  But there is no query logic inside of those created instances and the wrapped BO is translated into each row instance...giving the IBindingList interface and grids the interface they like while still only maintaining a single BO instance (again, the one that you have wrapped).

If this is ok, (perhaps you're using a shared table) then is there a way I can make the FieldPropertyChanged of the BO that is dropped on the form to be called?

Sure.  The BO that you have wrapped still respects all of the logic to which that BO is created.  So if you create a field changed event, then it will still get raised.

Hope that makes sense Smile

George Nentidis
George Nentidis
StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)
Group: Forum Members
Posts: 72, Visits: 251
Hi,

I have tried to work with this a lot. The thing is that the FieldChanged events do not raise.

I have attached a small sample application with its DB to help you reproduce this error. This is totaly a sample application and DB.

I have placed a CustomerBO in the form and bound it to a TextBox through a BussinessBindingSource. I have added an event handler for the FieldPropertyChanged event on the Customer instance, on the form. The event handler displays a MessageBox.

You can run the application, (if connected to the DB it should display my name), try and modify the value of the TextBox and change focus. The value of the BO changes, but the MessageBox is never displayed, since the event handler is never called. You can verify this by placing a breakpoint inside the event handler.

Also, if you place a breakpoint in the CustomerBO.Designer.cs on the property FullName, on the set method, you will see that when the value in the TextBox changes (after leaving the textbox), the set method is actually called. But when getting in the OnFieldPropertyChanged method, the loHandler is null. This is because a second instance of the CustomerBO is created somewhere else, and the BBS modifies that one. This causes the event of the BO I drop on the form to be ignored, since it is a different instance.

I hope all this can help you reproduce the error and fix it.

Thank you.

Attachments
BBSDuplicateBO.rar (97 views, 680.00 KB)
Paul Chase
Paul Chase
Advanced StrataFrame User (580 reputation)Advanced StrataFrame User (580 reputation)Advanced StrataFrame User (580 reputation)Advanced StrataFrame User (580 reputation)Advanced StrataFrame User (580 reputation)Advanced StrataFrame User (580 reputation)Advanced StrataFrame User (580 reputation)Advanced StrataFrame User (580 reputation)Advanced StrataFrame User (580 reputation)
Group: Forum Members
Posts: 414, Visits: 2.8K
I have had this same problem myself, when the business binding source creates a new instance of itself it does bubble up events back to the original copy so you are unable to handle any of the field changed events etc.. This really caused me alot of problems as well as I have logic in the field changed and changing event's as well as several custom events and the Data entry is all done in a Data Grid.

I ended up making something work for me but it would be great if the BBS could bubble events

P

Paul Chase
Paul Chase
Advanced StrataFrame User (580 reputation)Advanced StrataFrame User (580 reputation)Advanced StrataFrame User (580 reputation)Advanced StrataFrame User (580 reputation)Advanced StrataFrame User (580 reputation)Advanced StrataFrame User (580 reputation)Advanced StrataFrame User (580 reputation)Advanced StrataFrame User (580 reputation)Advanced StrataFrame User (580 reputation)
Group: Forum Members
Posts: 414, Visits: 2.8K
oops just noticed it should be does not bubble events up Smile
George Nentidis
George Nentidis
StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)StrataFrame User (136 reputation)
Group: Forum Members
Posts: 72, Visits: 251
No one posted anything in this topic for a while now. Does any one from Strata have an opinion on this issue?

When the BO events do not fire correctly, makes me gather more and more logic in form events, instead of gathering login inside the BO as it would be best.

I have just added some form events to correct this, so I thought I should ask, and refresh the date of the topic. Wink

Have you register this as a bug?

Thank you...

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Have you register this as a bug?

At present, the BBS does not bubble up the changed events.  This is a bug (of sorts) and we will make a change, but it will not be included in the 1.6.5 release.  This will require some core level changes and is something that can have down-stream effects, so this will be a change in the next update after the 1.6.5 build which is close to its final release state.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search