I have a CSLA object structure (a root Business object with a hierarchy of children, grandchildren etc.) where some of the required data to populate it is non-changing metadata and some of it is editable data. I have written a separate CSLA readonly object structure that loads the metadata, and this is cached so that it is not retrieved from the database each time. The problem I have is that the main object structure needs to be initialised from the metadata structure, and then the database needs to be called to fill in the editable data. This doesn't seem to fit with the CSLA DataPortal_Fetch call, which expects to load the whole object structure in one go. Ideally I need to be able to create my objects clientside, partially filling them in with the metadata, and only after that call the data portal to obtain the editable data and use it to finish off the population process.
Can anyone suggest a way of getting this to work? (I'm using CSLA 3.0.5)
Thanks,
Richard
Why not cache the metadata "server side", and that way you could fetch the objects in the normal CSLA method via the data portal and completely populate them on the server side?
You could certainly force your fetch method to run on the client, and during it's execution retrieve additional data over the data portal, but it might be less efficient (especially for building collections of objects if you are doing a round-trip per item in the collection).
> You could certainly force your fetch method to run on the client, and during it's execution retrieve additional data over the data portal
Thanks for your reply. Could I ask you how you see this working? I know I can use RunLocal on the DataPortal_Fetch method, forcing it to run on the client, but having done that, and written the code inside it that loads the metadata, how could I write code at the end of the locally running DataPortal_Fetch that then retrieves additional data over the data portal?
Thanks for any additional help
Richard
You'd use a second, private read-only object to go get the data. So your object's DP_F would be like this:
[RunLocal]
private void DataPortal_Fetch()
{
var cache = CachedData.GetData();
// load fields from cache
var server = ServerData.GetData(...);
// load fields from server
}
The ServerData class would be a standard read-only object, but it would be private to your actual business object (so you don't clutter the namespace).
Thanks for the replies. The actual scenario is a bit more complicated than my initial post, where I was trying to pick out the essentials in order to ask a coherent question; but the answers have given me a good steer as to the direction I should be heading in. Thanks again!
Richard
There are a few possible solutions, depending on your requirements.
Copyright (c) Marimer LLC