I am sure there must be a valid reason for the below code found in the Csla.Server.SimpleDataPortal class specifically in the Fetch and Create methods.
There is this explicit condition for the criteria of int type as the code below indicates. If an int is passed as a parameter it is calling the parameterless data portal Fetch method.
// tell the business object to fetch its data
if (criteria is int)
What are the reasons for this? We are using the 3.7.1 version.
I haven't looked at the code of SimpleDataPortal, but from your perspective, here is how the Criteria thing works.
When calling DataPortal.Fetch : (This is for Synchronous calls - since you did not mention Silverlight in your post)
1. If you have no parameters to pass for your query you simply do this:
2. If you a single parameter, like an Id (whatever type it may be):
DataPortal.Fetch<YourObjectType>(new SingleCriteria<YourObjectType, YourParameterType>(YourParameterName));
3. If you have more than one parameter to pass, you create your own Criteria class and use that instead of the "built-in" SingleCriteria.
Of course, that is in your Factory methods. In your DataAccess code, then you have to provide the DataPortal_Fetch() method(s) that match the call(s) you are making. You can have more than one, as long as number and/or type of parameters make the Method Signatures different.
This is explained in the Expert 2008 Business Objects book, and there's some history to the code.
Originally (years ago) CSLA required a criteria value. Around 2004 I enhanced the data portal to make the criteria value optional - but didn't want to break a set of low-level provider code for backward compatibility reasons. To avoid breaking that code, CSLA still does pass a criteria value - just a value that is otherwise invalid (an int), because a criteria value must implement ICriteria to be valid.
So the check for an int is really a check for a specific invalid value, that is used as a flag that is a placeholder for "no criteria".
All this changes in CSLA 4. CSLA 4 removes the requirement for ICriteria, and allows any single primitive or serializable value to be used as a criteria value. This means an int becomes a valid criteria value in CSLA 4.
Thanks Rocky. That explained it.
Copyright (c) Marimer LLC