Skip to content

Commit

Permalink
Added overload of WithTableValuedParameter that doesn't take a table …
Browse files Browse the repository at this point in the history
…name, as it can be passed on the DataTable.

Added release not indicating the DataTable is now supported.
Fixes #93
  • Loading branch information
abe545 committed Apr 27, 2017
1 parent 66899b0 commit ab0b022
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,30 @@ public static TSP WithTableValuedParameter<TSP, TRow>(this TSP sp,
return (TSP)sp.CloneWith(new TableValuedParameter(name, table, typeof(TRow), tableTypeName, tableTypeSchema));
}

/// <summary>
/// Clones the given <see cref="StoredProcedure"/>, and associates the <see cref="DataTable"/> items
/// as a Table Valued Parameter.
/// </summary>
/// <typeparam name="TSP">The type of <see cref="StoredProcedure"/> to associate the Table Valued Parameter with.</typeparam>
/// <param name="sp">The <see cref="StoredProcedure"/> to clone.</param>
/// <param name="name">The name of the Table Valued Parameter in the stored procedure.</param>
/// <param name="table">The <see cref="DataTable"/> to pass in the Table Valued Parameter. Make sure the <see cref="DataTable.TableName"/> is set,
/// as that will be used to identify the TVP's type in the database.</param>
/// <returns>A copy of the <see cref="StoredProcedure"/> that has the Table Valued Parameter set.</returns>
/// <remarks>StoredProcedures are immutable, so all the Fluent API methods return copies.</remarks>
public static TSP WithTableValuedParameter<TSP>(this TSP sp,
string name,
DataTable table)
where TSP : StoredProcedure
{
Contract.Requires(sp != null);
Contract.Requires(!string.IsNullOrWhiteSpace(name));
Contract.Requires(table != null);
Contract.Ensures(Contract.Result<TSP>() != null);

return (TSP)sp.CloneWith(new TableValuedParameter(name, table));
}

/// <summary>
/// Clones the given <see cref="StoredProcedure"/>, and associates the <see cref="DataTable"/> items
/// as a Table Valued Parameter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public TableValuedParameter(string name, DataTable data)
Contract.Requires(!string.IsNullOrWhiteSpace(name));
Contract.Requires(data != null);

if (string.IsNullOrWhiteSpace(data.TableName))
throw new NotSupportedException("When passing a DataTable, either set its TypeName to the TVP's type, or pass it in as one of the parameters.");

ParameterName = name;
this.data = data;
this.TypeName = data.TableName;
Expand Down
1 change: 1 addition & 0 deletions CodeOnlyStoredProcedures.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Code Only Stored Procedures will not create any Stored Procedures on your databa
<releaseNotes>2.4.0
Added support for binary blobs for both results and parameters by using a byte array.
Fixes bug where output parameters can not be used if the stored procedure returns results.
Added support for using DataTable to pass a Table-Valued Parameter

2.3.0
Can now opt in to not clone the database connection before executing a StoredProcedure.
Expand Down

0 comments on commit ab0b022

Please sign in to comment.