I am running a csla business dll on a windows service. We then connect to this service using the CSLA Data Portal Proxy.
Worryingly I have noticed that it works differently if I connect directly to the same business dll via a direct db connection or via the web service.
I have a BusinessListBase collection which I populated using the get list. This is kept locally on the client. I then add a BusinessBase object to this collection and call the BusinessListBase.Save and the object is inserted. If I call the save again, it is inserted agian, with no changes.
If I connect directly to the database from the client and do the same operation I get an Insert, then an update.
What is going on?
Save() returns a value. That value is the new object generated as a result of the Save(). You must use that result:
_object = _object.Save();
In older versions of CSLA you could cheat and not use the result when using a local data portal, but in all current versions you must use the result with local or remote data portal configurations.
Thats great Rocky, and fixes one issue, next question:
I have this method
Private static BusinessCollection _CollectionOfObjects;
Public static void (BusinessObject_Add(BusinessObject myObject)
{
_CollectionOfObjects.add(myobject);
_ CollectionOfObjects = _CollectionOfObjects.Save();
}
My collection is now correct, but how do I ensure that the object I passed in is updated from the object that has been inserted within the collection.
After you do a Save() you need to ensure that anything
referencing the collection gets the new reference (any forms, etc).
Rocky
You really can’t do what you are doing – you need to
return the new collection reference so the caller can update their reference.
If you want to save individual objects as you add them to a
collection, you might find that EditableRootListBase is the simpler base class,
instead of BusinessListBase, which is designed to save a batch of object
changes at once.
Rocky
I understand what you are saying, but I need to save the object to the db to get its key (indentity), as this is needed by other objects. So there is no way for me to reference the object from the collection after the save, other than using the original object as I won't know which one it was in the collection.
I will have a look at the use of EditableRootListBase. What I have is now working, just looks like a major hack.
Copyright (c) Marimer LLC