Hi
Is it only possible to get a TRUE/FALSE response back from a CommandObject?
Would it not be practical to have it return any data-type?
Perhaps I am using it wrong, but what I wanted to do is to a "CountOrders" kind of operation and I thought the CommandObject would be a perfect choice in the CSLA framework. Or what object should I use to just execute a simple command that returns a int?
i my case, the GetStatistics() operation would on the server side just do a "Select Count(*) FROM WHERE..." operation and return a int value.
I think creating a full blown "ReadOnly Root object" would be overkill for a simple operation like this.
Perhaps a NameValueList object would work, but I find that a bit ugly solution.
Hi sune42,
FWIW, I almost posted about the same question yesterday :) It was my first time needing something like "Select Count(*) From ... Where..." in a project using CSLA.
I copied the example CommandOjbect class from Chapter 7 to get started. That class's public Execute() method returns a boolean. I changed things around so it would return an int and also accept a couple args that I could use in my WHERE clause.
Then in the DataPortal_Execute method I put in the data access code, get the result and store it in my _result field.
Seems to work just fine. Hope I'm not doing anything wrong or pointing you in the wrong direction.
Regards,
Mike
If all you want to do is retrieve a value or a set of values, I'd use a ReadOnlyBase-derived object. That's the purpose of that base class, and it is often lighter-weight than a CommandBase-derived object.
Remember that "weight" is defined by the number and type of instance fields in your class - nothing else matters.
With a ROB you can define exactly the criteria needed to define the request and send only those fields to the server, then the ROB itself contains exactly the fields needed to return the results.
With CommandBase, the criteria and result fields are both defined in the command object - so the empty result fields are serialized to the server, and the now-useless criteria fields are serialized back to the client.
Where CommandBase really shines (imo) is in two areas:
In the book I really only show an example of #1 - through the Exists() commands as discussed in Chapter 8. But the templates, as discussed in Chapter 7, show the model for #2, which is where I think the real power of CommandBase comes into play.
Thanks for that excellent explaination!
Now I know what to do.
I thought the Command object would be lighter as it has a more specific purpose.
I guess I just assumed that CommandBase would be lighter too. I apreciate the explanation.
Mike
Copyright (c) Marimer LLC