You didn't mention which version of SQL Server you're using... but assuming it's a current version you could use the STRING_SPLIT function:
https://learn.microsoft.com/en-us/sql/t-sql/functions/string-split-transact-sql?view=sql-server-2017
Essentially, convert your list of values in to a delimited string. Send that in and split it. Ideally you should probably use table type, but this might suit your needs
SQL Code
DECLARE @Array NVARCHAR(MAX) = '0,1,2,3,4,5,6,7,8,9,10';
DECLARE @TemporaryTable TABLE (
[Value] INT
);
INSERT INTO @TemporaryTable ( [Value] )
SELECT CONVERT(INT, [value]) FROM STRING_SPLIT(@Array, ',');
SELECT [Value] FROM @TemporaryTable
List<int> lstIds = new List<int>() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
C# Code
List<int> lstIds = new List<int>() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
using (var connection = new SqlConnection("Data Source=localhost;Initial Catalog=Testing;Integrated Security=True;"))
{
connection.Open();
using (var command = connection.CreateCommand())
{
command.CommandText = @"CREATE TABLE #TemporaryTable ( [Value] INT );";
command.CommandType = System.Data.CommandType.Text;
command.ExecuteNonQuery();
}
using (var command = connection.CreateCommand())
{
command.CommandText = @"INSERT INTO #TemporaryTable ( [Value] ) SELECT CONVERT(INT, [value]) FROM STRING_SPLIT(@Array, ',');";
command.CommandType = System.Data.CommandType.Text;
command.Parameters.Add(new SqlParameter("@Array", string.Join(",", lstIds)));
command.ExecuteNonQuery();
}
using (var command = connection.CreateCommand())
{
command.CommandText = @"SELECT COUNT(1) FROM #TemporaryTable";
command.CommandType = System.Data.CommandType.Text;
int count = Convert.ToInt32(command.ExecuteScalar());
}
}