Use Table-Valued Parameters
What this page covers#
This page shows how to pass a table-valued parameter.
Example#
using System.Data; var table = new DataTable(); table.Columns.Add("UserId", typeof(int)); table.Rows.Add(42); table.Rows.Add(43); var parameters = new MooParams() .AddTableValuedParameter("@UserIds", table, "dbo.udt_UserIds"); var users = await db.ListAsync<User>( "dbo.usp_User_ListByIds", parameters);
Why TVPs are useful#
TVPs are useful when a stored procedure needs a set of rows as one parameter.
When not to use a TVP#
If your real goal is to load many rows straight into a table, consider db.Bulk.WriteToTableAsync(...) instead.