The specified table with the MONO cs parameter

I have simple code to create a SqlParameter for Table Valued Type. This code works fine with .NET 4.0. The problem with MONO CS (3.12.0), I can’t just compile the same code in MONO.

static SqlParameter GetDataTableParam(string _tableName, DataTable _dt)
{
    SqlParameter tValue = new SqlParameter();
    tValue.ParameterName = "@dr" + _tableName; //@drFactory
    tValue.SqlDbType = SqlDbType.Structured;
    tValue.Value = _dt;

    tValue.TypeName = string.Format("dbo.{0}Item", _tableName);  //MONO CS is giving error at this line
    return tValue;
}

Mono compiler giving me this error:

Error CS1061: Type `System.Data.SqlClient.SqlParameter' does not contain a definition for `TypeName' and no extension method `TypeName' of type `System.Data.SqlClient.SqlParameter' could be found. Are you missing an assembly reference? (CS1061)

This code simply tries to create a parameter for the TableValued Type and pass the data table to the SQL insert statement.

I know that the error can be resolved if I use a stored procedure, but in my case it is not possible to create a merge SP insert for each table.

So please help me if there is any work around this issue.

. , MONO System.Data.SqlClient.SqlParameter TypeName. , , :

The table type parameter '@drFactory' must have a valid type name.

0
1

MONO SqlParameter TypeName, .

, Reflection TypeName:

 SqlParameter tValue = new SqlParameter("@dr" + _tableName, _dt);
 tValue.SqlDbType = SqlDbType.Structured;

 System.Reflection.PropertyInfo propertyInfo = tValue.GetType().GetProperty("TypeName");
 propertyInfo.SetValue(tValue, "dbo.factoryItem", null);
0

All Articles