Hi
I have a BusinessListBase collection containing BusinessBase children. I am using the template mentioned in the book under the title of "Editable Root Collection". Using windows form I bind the object to a datagrid and everything works well up to the point I want to save the root. An encounter an error with the following message:
DataPortal.Update failed (System.NotSupportedException: Invalid operation - update not allowed
at Csla.BusinessListBase`2.DataPortal_Update() in C:\Visual Studio Projects\cslacs\Csla\BusinessListBase.cs:line 1155
at dm(Object , Object[] )
at Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Object[] parameters) in C:\Visual Studio Projects\cslacs\Csla\Reflection\MethodCaller.cs:line 357)
Does anybody know what the problem is?
You must override the DataPortal_Update() method. Look at Chapter 17 or 18 for an example.
CSLA has no idea what kind of database you are using (or if you even have a database), so you need to open the database before trying to save the child objects - and this is the reason for overriding that method.
Thanks
I did what you said and it worked.
Hello,
Is this a valid save scenario for ERL?
protected override void DataPortal_Update()
{
RaiseListChangedEvents = false;
for (int index = 0; index < DeletedList.Count; index++)
{
DeletedList[index] = DeletedList[index].Save();
}
// Clearing the list... Is this okay for nlevel undo?
DeletedList.Clear();
for (int index = 0; index < Items.Count; index++)
{
Items[index] = Items[index].Save();
}
RaiseListChangedEvents = true;
}
And this for an ECL?
protected override void Child_Update(params object[] parameters)
{
RaiseListChangedEvents = false;
foreach (Member item in Items)
{
DataPortal.UpdateChild(item, parameters);
}
foreach (Member item in DeletedList)
{
DataPortal.UpdateChild(item, parameters[1]);
}
// Clear deleted list?
RaiseListChangedEvents = true;
}
Thanks
-Blake Niemyjski
No, you can't call Save() on a child object. If the ERL is constructed correctly, it will contain child objects that will throw an exception when you try to save them.
Hi,
EditableRootList is a collection of Root Editable objects and the list will automatically call Save if a row ("root") is dirty and you move to another row in the list or immediate Deletion if you remove a row.
Alternatively you may call the SaveItem(int index) method on the list. This method will save the root object and replace the entry in list with the new object returned from save.
Hello,
In this case the List is an ERL and the children are ER's and so you can call Save(). It would be the same thing as calling Save normally (ER = ER.Save()). I don't remember why exactly I had to override this behavior, but there was a couple of things that didn't work until I implemented this.
@JonnyBee
Are you thinking of a DynamicRootList, This isn't the default Save behavior of ERL or an ER.
Thanks
-Blake Niemyjski
Putting root objects in a BLB is not supported.
The only supported list of root objects is ERLB, or a simple type like a serializabe List<T> or something like that (MobileList<T> for Silverlight).
Hello,
This seems really backwards to me. Your are saying that you can't put an EditableRoot in an EditableRootList?
Thanks
-Blake Niemyjski
That's what I'm saying, yes. Language is tricky sh*t
http://www.lhotka.net/article.aspx?id=4484d01a-faa9-4220-a5c9-065e7b43b0af
Copyright (c) Marimer LLC