Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #11: Added support for returning a DBDataReader based on xavier… #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions EntityFrameworkExtras.EF5/DatabaseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,29 @@ public static IEnumerable<T> ExecuteStoredProcedure<T>(this Database database, o
return result;
}

/// <summary>
/// Executes the specified stored procedure against a database
/// and returns a DbDataReader. Used for procedures returning multiple result sets.
/// </summary>
/// <param name="database">The database to execute against.</param>
/// <param name="storedProcedure">The stored procedure to execute.</param>
/// <returns></returns>
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<SqlParameter> sqlParameters, object storedProcedure)
{
foreach (SqlParameter sqlParameter in sqlParameters.Where(p => p.Direction != ParameterDirection.Input))
Expand Down
23 changes: 23 additions & 0 deletions EntityFrameworkExtras.EF6/DatabaseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,29 @@ public static IEnumerable<T> ExecuteStoredProcedure<T>(this Database database, o
return result;
}

/// <summary>
/// Executes the specified stored procedure against a database
/// and returns a DbDataReader. Used for procedures returning multiple result sets.
/// </summary>
/// <param name="database">The database to execute against.</param>
/// <param name="storedProcedure">The stored procedure to execute.</param>
/// <returns></returns>
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<SqlParameter> sqlParameters, object storedProcedure)
{
foreach (SqlParameter sqlParameter in sqlParameters.Where(p => p.Direction != ParameterDirection.Input))
Expand Down
23 changes: 23 additions & 0 deletions EntityFrameworkExtras/DatabaseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,29 @@ public static IEnumerable<T> ExecuteStoredProcedure<T>(this Database database, o
return result;
}

/// <summary>
/// Executes the specified stored procedure against a database
/// and returns a DbDataReader. Used for procedures returning multiple result sets.
/// </summary>
/// <param name="database">The database to execute against.</param>
/// <param name="storedProcedure">The stored procedure to execute.</param>
/// <returns></returns>
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<SqlParameter> sqlParameters, object storedProcedure)
{
foreach (SqlParameter sqlParameter in sqlParameters.Where(p => p.Direction != ParameterDirection.Input))
Expand Down