Is there any sample code that shows how to create an editable root object collection? In the project tracker sample I am finding lots of child editable/readonly collection but no parent root level.
I tried implementing using the BusinessListBase but am running into errors complaining about being a child object.
BLB is what you need, you still need to make sure it’s
containing objects are marked as Child.
Sergey Barskiy
Principal Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: AZS
[mailto:cslanet@lhotka.net]
Sent: Wednesday, January 21, 2009 2:41 PM
To: Sergey Barskiy
Subject: [CSLA .NET] How to create a Root object collection
Is there any sample code that shows how to create an editable root object
collection? In the project tracker sample I am finding lots of
child editable/readonly collection but no parent root level.
I tried implementing using the BusinessListBase but am running into errors complaining
about being a child object.
Thank you for the info:
I am getting this error message when I try to save the data when my prototype app tries to save the data using the data portal object. I am still looking for some sample code that actually save the data to a database.
DataPortal.Update failed (System.NotSupportedException: Invalid operation - update not allowed
at Csla.BusinessListBase`2.DataPortal_Update() in C:\Visual Studio Projects\csla\cslacs\Csla\BusinessListBase.cs:line 1143
at dm(Object , Object[] )
at Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Object[] parameters) in C:\Visual Studio Projects\csla\cslacs\Csla\Reflection\MethodCaller.cs:line 297)
Thanks,
Ahmad
Rocky,
I have looked at the sample app. As far as I can tell all the collection objects are children collections and are populated by the parent object. Please correct me if I am wrong. I just recently purchased your 2005 business object book right before the 2008 was available and don't have access to the 2008 version.
All I am trying to do is create an updatable root collection list (using BusinessListBase) and ulitmately bind it to a grid on a webform. I am trying to deliver this prototype by this Friday. Any help in providing some sample code will be appreciated.
Thanks,
Ahmad
Both EditableRootListBase (ERLB) and BusinessListBase (BLB) can be bound to a data grid for editing.
The difference is that with BLB, you save all changes to the list -- any and all changed rows -- in a single DataPortal_Update() call. Your UI will need some sort of "Save" button to apply changes to the list (and you would typically call BeginEdit() on the list before binding so that changes to the list can be undone, in which case you'll also want some sort of Undo button). Typically you'll need to unbind when saving and rebind afterwards -- search for RebindUI for lots of discussion on this.
On the other hand, ERLB will try to save the changes to each row as the focus moves from row to row. The grid will manage the saving and you don't really have manual save/undo support (although the grid may allow an individual row to be undone via some key sequence, but it's doing it by itself and not using CSLA's undo support for this)
In both cases, you can't call Save() yourself directly on items in the list. With BLB, you call Save() on the list itself to save the entire list. With ERLB, you can call SaveItem() on the list to save individual items.
Typically, an ERLB is fetched -- e.g. you implement DataPortal_Fetch in a derived class and it is passed an empty list which you populate with child ojects. I could be wrong but I didn't see a DataPortal_Create() implementation for it but I'll double check. I ran into this myself and implemented my own static Create() factory function for my ERLB-derived class when I needed it.
You mentioned using a Web Forms grid.
ERLB is designed only for Windows forms grids.
I recommend you stop trying to use it.
Just create a root BO that does nothing except contain a standard child collection. Then when you fetch the root all it does is fetch the collection. Then bind the collection to the web grid normally.
Joe
Oops, I missed the WebForm reference in the OP's last post. Yes, Joe is quite correct in that ERLB is not (at all) well-suited for this. Mea culpa.
Any suggestions on on how to aproach this problem. I am looking for sample code implementing a root level object collection (editable) that can be fully bindable to a Webform grid.
As I am trying to do this using the "BusinessListBase" object, I am running into problem when I save the collection. I have a feeling that I am not doing something right with the DataProtal.Update of the collection object.
In your DataPortal_Update(), how are you saving the individual items?
You can either use the child data portal (new), or you should be actually doing the work to explicitly save/delete each item in the list instead of trying to call Save() directly on them.
To use the child data portal (which I haven't yet ), I think you implement Child_DeleteSelf, Child_Insert, and Child_Update overrides in your child object, and then just call Child_Update() on your BLB derived list class in your DataPortal_Update() method. These overrides should to the actual work of persisting the changes to each child in the list to the database.
I have manual code to do the saving, and it looks something like this (very much like the BLB Child_Update() method). The "Update" method below is my own internal method that takes a transaction I have started and does the actual work of writing the changes the database.
// Save deleted items first
foreach (C deletedObject in DeletedList){
// Objects must delete themselvesdeletedObject.Delete(transaction);
}
foreach (C businessObject in this){
businessObject.Update(transaction);
}
DeletedList.Clear();
Have you looked at chapter 7 of the 2005 book, or chapters 4-5
of the 2008 book?
These chapters walk through all the object stereotypes,
discussing how to create each one. An editable root list is one of the
stereotypes that’s covered, including all the code regions required for
implementing that type of object.
Rocky
From: AZS
[mailto:cslanet@lhotka.net]
Sent: Thursday, January 22, 2009 11:43 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] RE: How to create a Root object collection
Any suggestions on on how to aproach this problem. I am looking for sample
code implementing a root level object collection (editable) that can be fully
bindable to a Webform grid.
As I am trying to do this using the "BusinessListBase" object, I am
running into problem when I save the collection. I have a feeling that I am not
doing something right with the DataProtal.Update of the collection object.
Copyright (c) Marimer LLC