UnitTest reports SQL error - data type not found

I am using this code:

using (var unitOfWork = this.unitOfWorkFactory.Create())
{
    var tagParam = new SqlParameter
                       {
                           ParameterName = "@tagList",
                           SqlDbType = System.Data.SqlDbType.Structured,
                           Value = tags.ToTVP(),
                           TypeName = "[dbo].[TagList]"
                       };

    unitOfWork.Context.Database.ExecuteSqlCommand("exec sp_InsertTagList @tagList", tagParam);
    // unitOfWork.Context.Database.ExecuteSqlCommand("INSERT INTO dbo.Tags SELECT Name FROM @tagList", tagParam);
}

      

ToTvp

is just an extension method that does it DataTable

for me from a list of items.

I am getting this error:

Test method InspiredBlog.UnitTests.UnitTest1.TestMethod1 threw exception: System.Data.SqlClient.SqlException: column, parameter or variable @tagList .: Cannot find data type dbo.TagList.

I have created a table type in my database.

CREATE TYPE TagList AS TABLE 
(
    Name VARCHAR(MAX)
)
GO

      

I don't know why this error is being returned!

I can easily create a SQL query and execute in SSMS

+3
c # sql-server entity-framework


source to share


No one has answered this question yet

Check out similar questions:

996
Find all tables containing column with specified name - MS SQL Server
351
Converting datetime2 datatype to datetime datatype results in outlevel value
five
Using DBNull.Value with SqlParameter without sqlDbType knowledge?
2
Direct filling of varchar SQL Server data via ADO.Net
1
Column level encryption, select query in stored procedure with clause where does not work
1
Error while inserting data into SQL table
1
LogParser: data type of SQL table column "X" is incompatible with SELECT clause member "cs-username" (STRING type)
1
SQL UDT Type parameter passed in C #
0
How do I pass a data table created from ExcelDataReader to a SQL Server stored procedure as a parameter?
0
SQL EXEC SP with parameter to TEMP table



All Articles
Loading...
X
Show
Funny
Dev
Pics