Passing user-defined table type (SQL Server)

Mar 27, 2013 at 4:00 PM
Hi,

I also posted at stackoverflow, but i think i will have more chance for a reply here (since i can not add a fluentdata tag).

So, can i pass a user-defined table type to a stored procedure using fluentdata ?
.dbContext().Sql("MyStoredProcedureName").Parameter("MyUserDefinedTableType", myObject, DbTypes. ?????)
Thanks in advance
Coordinator
Mar 29, 2013 at 11:13 AM
User-defines table type is a SQL Server specific type that is not available through the generic ADO.NET provider that FluentData depends on. This means that you need to do this:

var builder = dbContext.StoredProcedure("DeleteProductsByIds");
var sqlCommand = (SqlCommand)builder.Data.Command.Data.InnerCommand;
sqlCommand.Parameters.Add("@ProductIds", SqlDbType.Structured).Value = productIds;
builder.Execute();

The productIds would be a datatable:
var productIds = new DataTable();
productIds.Columns.Add("ProductId", typeof(int));
productIds.Rows.Add(productIds.NewRow()["ProductId"] = 1);
productIds.Rows.Add(productIds.NewRow()["ProductId"] = 2);
productIds.Rows.Add(productIds.NewRow()["ProductId"] = 3);