I tried something like this (it works)
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using MyUDT = [.Net CLR type of the udt];
namespace TestSqlUDT
{
class Program
{
static void Main(string[] args)
{
string tableName = "....";
string idName = "....";
string udtFieldName = "....";
string connectionString = @"....";
string commandText = string.Format("UPDATE {0} set {1} = @udtvalue where {2} = @id", tableName, udtFieldName, idName);
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlCommand command = new SqlCommand(commandText, connection))
{
connection.Open();
MyUDT myUDT = MyUDT.Parse(@"xyz");
//SqlParameter paramValue = CreateParameter(command, "@udtvalue", System.Data.DbType.Object, 0, ParameterDirection.Input, false, 0, 0, String.Empty, DataRowVersion.Default, myUDT);
//paramValue.SqlDbType = SqlDbType.Udt;
//paramValue.UdtTypeName = myUDT.GetType().Name;
SqlParameter paramValue = CreateParameter(command, "@udtvalue", System.Data.DbType.String, 0, ParameterDirection.Input, false, 0, 0, String.Empty, DataRowVersion.Default, myUDT);
command.Parameters.Add(paramValue);
SqlParameter paramId = CreateParameter(command, "@id", System.Data.DbType.Guid, 0, ParameterDirection.Input, false, 0, 0, String.Empty, DataRowVersion.Default, new Guid("63ACDC3B-9798-4625-AA97-99A427B73AFA"));
command.Parameters.Add(paramId);
command.ExecuteNonQuery();
}
}
}
private static SqlParameter CreateParameter(SqlCommand command, string name, DbType type, int size, ParameterDirection direction, bool nullable, byte precision, byte scale, string sourceColumn, DataRowVersion sourceVersion, object value)
{
SqlParameter param = command.CreateParameter();
param.ParameterName = name;
if ((type.Equals(DbType.Object)) && (value is byte[]))
{
param.SqlDbType = SqlDbType.Image;
}
else
{
param.DbType = type;
}
param.Size = size;
param.Direction = direction;
param.IsNullable = nullable;
param.Precision = precision;
param.Scale = scale;
param.SourceColumn = sourceColumn;
param.SourceVersion = sourceVersion;
param.Value = (value == null) ? DBNull.Value : value;
return param;
}
}
}
If you need the schema name, maybe you could store it like other data in PersistenceInfoProvider? The catalog name ... udt's have to be registered per database (catalog), so i assume they are database bound (correct me if i'm wrong).