I need to use Table Valued Parameter with string query
I have the following code
string query = "SELECT * FROM Tabla1 T1 INNER JOIN @listItems T2 ON T2.Id = T1.Id";
var results = sqlConnection.Query(query , new TableValuedParameter<string>("@listItems", "string_list_Type", valuesList));
the variable valueList is a List
The execution give me a error: "Could not find stored procedure"
Is posible usa table valued parameters without use procedure ?
thanks regards
Table-valued parameters are declared by using user-defined table types. You can use table-valued parameters to send multiple rows of data to a Transact-SQL statement or a routine, such as a stored procedure or function, without creating a temporary table or many parameters.
Dapper is a micro ORM or it is a simple object mapper framework which helps to map the native query output to a domain class or a C# class. It is a high performance data access system built by StackOverflow team and released as open source.
Without seeing full code sample it is hard to tell what the problem could be. Consider this, which executes perfectly fine:
First, TVP definition
CREATE TYPE [dbo].[TVPSTRING] AS TABLE(
[VALUE] NVARCHAR(MAX) NULL
)
Then sample Dapper code:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using Dapper;
namespace CPTVP
{
class Program
{
static void Main(string[] args)
{
var dt = new DataTable();
dt.Columns.Add("StringsStringsEverywhere", typeof(string));
foreach (int i in Enumerable.Range(0,10))
{
dt.Rows.Add(string.Format("{0:0000}", i));
}
using (var conn = new SqlConnection("Data Source=.;Initial Catalog=Scratch;Integrated Security=true;"))
{
Console.WriteLine(String.Join("\n", conn.Query<string>("SELECT * FROM @tvpstr", new {tvpstr=dt.AsTableValuedParameter("dbo.TVPSTRING")})));
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With