Search code examples
asp.netstored-proceduresormsubsonicsubsonic3

Subsonic 3: Calling Stored Procedures as functions in ASP.NET 4


It seems that the only way to call an Sp with Subsonic 3 is as follows:

StoredProcedure sp = new StoredProcedure("NameOfSP");
mySqlCommand.Parameters.Add("@MyVar", SqlDbType.Int).Value = 1;

I remember some time ago that it was possible to call a stored procedure as a function:

SPs.NameOfSP(1);

Is this still possible with SubSonic? If not, what SP wrapper would provide this functionality?


Solution

  • There is a T4 template named "StoredProcedures.tt" that generates the methods to match your stored procedures. If that file is missing, you can re-fetch it from here. The way the template is currently set up, the method takes in the parameters and sets them for you, then returns a StoredProcedure object instance, and I think you might have to call .Execute() on it, like:

    SPs.NameOfSP(1).Execute();
    

    but you could easily modify that T4 template to call .Execute() within the SP method call.