I have the following tsql function:
ALTER FUNCTION [dbo].[fn_MyFunc] (
@AccountId varchar(50)
)
returns bit
as
begin
declare @IsEligible bit
--some calculation
return @IsEligible
end
Using c#, is that the way to call this tsql function and get its returned value?
Database database = DatabaseFactory.CreateDatabase("DB");
using (DbCommand dbCommand = database.GetStoredProcCommand("fn_MyFunc"))
{
database.AddInParameter(dbCommand, "@AccountId", DbType.String, "1234");
bool returnedVAlue = (bool)dbCommand.ExecuteScalar();
}
Because you are calling a function you would have to call it using inline sql rather than a stored procedure. So rather than calling a stored proc you would call
You could also create a stored procedure that just wraps up the call to the function.