/// <summary> /// Executes the specified stored procedure against a database. /// </summary> /// <param name="database">The database to execute against.</param> /// <param name="storedProcedure">The stored procedure to execute.</param> public static void ExecuteStoredProcedure(this Database database, object storedProcedure) { if (storedProcedure == null) { throw new ArgumentNullException(nameof(storedProcedure)); } var info = StoredProcedureParser.BuildStoredProcedureInfo(storedProcedure); // ReSharper disable once CoVariantArrayConversion database.ExecuteSqlCommand(info.Sql, info.SqlParameters); SetOutputParameterValues(info.SqlParameters, storedProcedure); }
/// <summary> /// Executes the specified stored procedure against a database and returns an enumerable of T /// representing the data returned. /// </summary> /// <typeparam name="T">Type of the data returned from the stored procedure.</typeparam> /// <param name="database">The database to execute against.</param> /// <param name="storedProcedure">The stored procedure to execute.</param> /// <returns></returns> public static IEnumerable <T> ExecuteStoredProcedure <T>(this Database database, object storedProcedure) { if (storedProcedure == null) { throw new ArgumentNullException(nameof(storedProcedure)); } var info = StoredProcedureParser.BuildStoredProcedureInfo(storedProcedure); // ReSharper disable once CoVariantArrayConversion var result = database.SqlQuery <T>(info.Sql, info.SqlParameters).ToList(); SetOutputParameterValues(info.SqlParameters, storedProcedure); return(result); }