I have worked around this by modifying Custom_DataAccessAdapterTemplate.template to include the following code, this one does Scalar Functions, I have one that does ResultSets as well it just changes the ExecuteScalar line.
This function can be called directly if necessary but we generally use a code file in our data layer that doesn't get modified, i.e. 2 class scenario to provide typed scalar functions and functionality similar to a TypedList.
#region User Defined Function related routines
/// <summary>
/// Calls the specified function in the SqlServer database. If a transaction is in progress, it will participate in
/// that transaction.
/// </summary>
/// <param name="userDefinedFunctionToCall">Stored procedure to call</param>
/// <param name="parameters">array of parameters to specify</param>
/// <returns>the scalar result of the function as an object</returns>
public virtual object CallUserDefinedFunction(string userDefinedFunctionToCall, SqlParameter[] parameters)
{
string functionCallSql = "select " + HandleCatalogNameStoredProcedure(userDefinedFunctionToCall);
string sqlParams = "(";
object toReturn = null;
SqlCommand command = new SqlCommand(string.Empty);
command.Connection = (SqlConnection)base.GetActiveConnection();
if(base.IsTransactionInProgress)
{
command.Transaction = (SqlTransaction)base.PhysicalTransaction;
}
command.CommandType = CommandType.Text;
command.CommandTimeout = base.CommandTimeOut;
try
{
for(int paramEntry = 0; paramEntry < parameters.Length; paramEntry++)
{
command.Parameters.Add(parameters[paramEntry]);
sqlParams += parameters[paramEntry].ParameterName;
if (paramEntry < parameters.Length - 1)
{
sqlParams += " ,";
}
}
sqlParams += ")";
functionCallSql += sqlParams;
base.OpenConnection();
toReturn = command.ExecuteScalar();
}
finally
{
// clean up a dangling automaticly opened connection if needed.
if(!(base.KeepConnectionOpen || base.IsTransactionInProgress))
{
base.CloseConnection();
}
}
return toReturn;
}
#endregion
John