diff --git a/EntityFrameworkExtras.EF5/DatabaseExtensions.cs b/EntityFrameworkExtras.EF5/DatabaseExtensions.cs index bf47d95..505b162 100644 --- a/EntityFrameworkExtras.EF5/DatabaseExtensions.cs +++ b/EntityFrameworkExtras.EF5/DatabaseExtensions.cs @@ -52,6 +52,29 @@ public static IEnumerable ExecuteStoredProcedure(this Database database, o return result; } + /// + /// Executes the specified stored procedure against a database + /// and returns a DbDataReader. Used for procedures returning multiple result sets. + /// + /// The database to execute against. + /// The stored procedure to execute. + /// + public static System.Data.Common.DbDataReader ExecuteReader(this Database database, object storedProcedure) + { + if (storedProcedure == null) + throw new ArgumentNullException("storedProcedure"); + + var info = StoredProcedureParser.BuildStoredProcedureInfo(storedProcedure); + + using (var cmd = database.Connection.CreateCommand()) + { + cmd.CommandText = info.Sql; + cmd.Parameters.AddRange(info.SqlParameters); + + return cmd.ExecuteReader(); + } + } + private static void SetOutputParameterValues(IEnumerable sqlParameters, object storedProcedure) { foreach (SqlParameter sqlParameter in sqlParameters.Where(p => p.Direction != ParameterDirection.Input)) diff --git a/EntityFrameworkExtras.EF6/DatabaseExtensions.cs b/EntityFrameworkExtras.EF6/DatabaseExtensions.cs index 55b3140..664da04 100644 --- a/EntityFrameworkExtras.EF6/DatabaseExtensions.cs +++ b/EntityFrameworkExtras.EF6/DatabaseExtensions.cs @@ -52,6 +52,29 @@ public static IEnumerable ExecuteStoredProcedure(this Database database, o return result; } + /// + /// Executes the specified stored procedure against a database + /// and returns a DbDataReader. Used for procedures returning multiple result sets. + /// + /// The database to execute against. + /// The stored procedure to execute. + /// + public static System.Data.Common.DbDataReader ExecuteReader(this Database database, object storedProcedure) + { + if (storedProcedure == null) + throw new ArgumentNullException("storedProcedure"); + + var info = StoredProcedureParser.BuildStoredProcedureInfo(storedProcedure); + + using (var cmd = database.Connection.CreateCommand()) + { + cmd.CommandText = info.Sql; + cmd.Parameters.AddRange(info.SqlParameters); + + return cmd.ExecuteReader(); + } + } + private static void SetOutputParameterValues(IEnumerable sqlParameters, object storedProcedure) { foreach (SqlParameter sqlParameter in sqlParameters.Where(p => p.Direction != ParameterDirection.Input)) diff --git a/EntityFrameworkExtras/DatabaseExtensions.cs b/EntityFrameworkExtras/DatabaseExtensions.cs index be63f47..e61e40e 100644 --- a/EntityFrameworkExtras/DatabaseExtensions.cs +++ b/EntityFrameworkExtras/DatabaseExtensions.cs @@ -52,6 +52,29 @@ public static IEnumerable ExecuteStoredProcedure(this Database database, o return result; } + /// + /// Executes the specified stored procedure against a database + /// and returns a DbDataReader. Used for procedures returning multiple result sets. + /// + /// The database to execute against. + /// The stored procedure to execute. + /// + public static System.Data.Common.DbDataReader ExecuteReader(this Database database, object storedProcedure) + { + if (storedProcedure == null) + throw new ArgumentNullException("storedProcedure"); + + var info = StoredProcedureParser.BuildStoredProcedureInfo(storedProcedure); + + using (var cmd = database.Connection.CreateCommand()) + { + cmd.CommandText = info.Sql; + cmd.Parameters.AddRange(info.SqlParameters); + + return cmd.ExecuteReader(); + } + } + private static void SetOutputParameterValues(IEnumerable sqlParameters, object storedProcedure) { foreach (SqlParameter sqlParameter in sqlParameters.Where(p => p.Direction != ParameterDirection.Input))