Can't save an Editable Root ListCan't save an Editable Root List
Old forum URL: forums.lhotka.net/forums/t/6398.aspx
dculler posted on Tuesday, February 10, 2009
I've created a simple Editable Root List called UserList to hold a collection of child User objects.
I created both of these using the EditableRootList VS object template that came w/ CSLA 3.6.1.
I've really only created the properties I need for the User class, and wrote the data access code for both UserList & User classes, and didn't really do anything else.
As there are no records currently in this table, I get an empty UserList as expected. When I try to add a new User object, set it's name and attempt to save the UserList like this:
UserList userList = UserList.GetUserList();
userList.Add(User.NewUser());
userList[0].Name = "Test User";
userList = userList.Save();
the following Csla.DataPortalException is thrown: DataPortal.Update failed (System.NotSupportedException: Invalid operation - update not allowed\r\n at Csla.BusinessListBase`2.DataPortal_Update()\r\n at dm(Object , Object[] )\r\n at Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Object[] parameters))"
From what I've read, I should be saving the list, as it's the root object, and it should be saving it's children. I've been looking through the book, and the Project Tracker example, and can't figure out what I'm doing wrong. Thanks in advance to anyone who can tell me what I'm missing.
rsbaker0 replied on Wednesday, February 11, 2009
Editable Root List Base (ERLB) derived classes are mainly intended for supporting editing a list in a grid, and the interaction with the grid will automatically cause the object associated with the current grid row to be saved when you leave the row for another row.
I'm not sure exactly what you are trying to do, but a BusinessListBase class is probably more appropriate.
You can save the items in an ERLB, but you essentially will have to loop through the list yourself and call SaveItem() on each item in the list.
I've found ERLB useful for some interesting scenarios, but usually it is the case that I explicitly DO NOT want the entire list to be atomicly saved and need some additional control over the saving (or failure to save) individual items in the list.
RockfordLhotka replied on Wednesday, February 11, 2009
You do need to override DataPortal_Update() in a BusinessListBase subclass. This is discussed in Chapters 3-4, and is necessary because CSLA has no idea how to open your database (via ADO.NET, L2S, EF, NHibernate or whatever - there's no way to know what you are using).
So you need to override the DataPortal_Update() method, open the database (or whatever), and call this.Child_Update() to trigger the children to save, and then close the database (or whatever).
dculler replied on Wednesday, February 11, 2009
Thanks for the help. I left out that this is a BusinessListBase derived class earlier. I was able to save when overriding DataPortal_Update()
Where I'm confused is that on page 190 of the book for 2008, third paragraph from the bottom it says that BusinessListBase provides a default implementation and that you should only need to override DataPortal_Update() for unusual scenarios.
Is it always necessary to override DataPortal_Update in BusinessListBase derived classes, or are there cases where you can use the default implementation?
RockfordLhotka replied on Wednesday, February 11, 2009
That’s a typo and is covered in the errata. That paragraph
refers to Child_Update(), which you should only have to override for unusual
scenarios.
Rocky
From: dculler
[mailto:cslanet@lhotka.net]
Sent: Wednesday, February 11, 2009 9:44 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Can't save an Editable Root List
Thanks for the help. I left out that this is a
BusinessListBase derived class earlier. I was able to save when
overriding DataPortal_Update()
Where I'm confused is that on page 190 of the book for 2008, third paragraph
from the bottom it says that BusinessListBase provides a default implementation
and that you should only need to override DataPortal_Update() for unusual
scenarios.
Is it always necessary to override DataPortal_Update in BusinessListBase
derived classes, or are there cases where you can use the default
implementation?
Vinodonly replied on Thursday, July 16, 2009
I'm getting a similar error and i checked on below site but was not able to find this error
http://www.apress.com/book/errata/1017
Can you pls guide me to the corrrect link and which pttracker object i should see which implements this correctly..Copyright (c) Marimer LLC