When creating a RAW CFQL method, I noticed the declaration of the parameters are losing their default NULL values compared to a traditional SEARCH method.
The generated procedure would thus not accept any null argument. Typically I would like to have:
CREATE PROCEDURE [dbo].[User_AdvancedSearch]
(
@townIds [nvarchar] (max) = NULL,
@townLabel [nvarchar] (256) = NULL
)
instead of
CREATE PROCEDURE [dbo].[User_AdvancedSearch]
(
@townIds [nvarchar] (max),
@townLabel [nvarchar] (256)
)
AS
SET NOCOUNT ON
DECLARE @sql nvarchar(max), @paramlist nvarchar(max)
SELECT @sql=
'SELECT 1,2'
SELECT @paramlist = 'townIds nvarchar (256),
@townLabel nvarchar (256)'
EXEC sp_executesql @sql
RETURN
The example used here is as follow
<cf:method name="AdvancedSearch">
<cf:body text="RAW(string[] townIds, string townLabel) " rawText="DECLARE @sql nvarchar(max), @paramlist nvarchar(max)

SELECT @sql=
'SELECT 1,2'
SELECT @paramlist = 'townIds nvarchar (256), 
 @townLabel nvarchar (256)'
EXEC sp_executesql @sql

" language="tsql" />
</cf:method>
1 - How can I have my parameter to default to NULL in a RAW method ?
Also I noticed that property giving the return type (Return Type Name) doesn't seem to be taken into account. The method generated returns void instead of the selected type and is located in the Entity class instead of the EntityCollection class.
I have read in this link 1 that For syntax: RAW(arguments). You have to specify the return type in the property grid
The method generated doesn't take into account this property and returns void as follow.
public static void AdvancedSearch(string[] townIds, string townLabel)
{
if ((townLabel == default(string)))
{
throw new System.ArgumentNullException("townLabel");
}
CodeFluent.Runtime.CodeFluentPersistence persistence = CodeFluentContext.Get(WcfServices.Model.Constants.WcfServices_ModelStoreName).Persistence;
persistence.CreateStoredProcedureCommand(null, "User", "AdvancedSearch");
persistence.AddParameter("@townIds", townIds);
persistence.AddParameter("@townLabel", townLabel);
System.Data.IDataReader reader = null;
try
{
persistence.ExecuteNonQuery();
}
finally
{
if ((reader != null))
{
reader.Dispose();
}
persistence.CompleteCommand();
}
}
2 - How can I have the RAW CFQL procedure to return according type ?
Thanks for your answer.
You should create a method SEARCH() RAW
:
<cf:method name="SearchRaw" body="SEARCH(string text1, string text2) RAW" rawBody="SELECT @text1" />
If you still want to create a method RAW
, you need to set parameters to be nullable and to specify the return type:
<cf:method name="SearchRaw" body="RAW(string text1, string text2)" rawBody="SELECT 1" returnTypeName="{0}.CustomerCollection">
<cf:parameter name="text1" nullable="true" />
<cf:parameter name="text" nullable="true" />
</cf:method>