In case anybody is looking for methods to convert from/to C# and SQL Server formats, here goes a simple implementation:
private readonly string[] SqlServerTypes = { "bigint", "binary", "bit", "char", "date", "datetime", "datetime2", "datetimeoffset", "decimal", "filestream", "float", "geography", "geometry", "hierarchyid", "image", "int", "money", "nchar", "ntext", "numeric", "nvarchar", "real", "rowversion", "smalldatetime", "smallint", "smallmoney", "sql_variant", "text", "time", "timestamp", "tinyint", "uniqueidentifier", "varbinary", "varchar", "xml" };
private readonly string[] CSharpTypes = { "long", "byte[]", "bool", "char", "DateTime", "DateTime", "DateTime", "DateTimeOffset", "decimal", "byte[]", "double", "Microsoft.SqlServer.Types.SqlGeography", "Microsoft.SqlServer.Types.SqlGeometry", "Microsoft.SqlServer.Types.SqlHierarchyId", "byte[]", "int", "decimal", "string", "string", "decimal", "string", "Single", "byte[]", "DateTime", "short", "decimal", "object", "string", "TimeSpan", "byte[]", "byte", "Guid", "byte[]", "string", "string" };
public string ConvertSqlServerFormatToCSharp(string typeName)
{
var index = Array.IndexOf(SqlServerTypes, typeName);
return index > -1
? CSharpTypes[index]
: "object";
}
public string ConvertCSharpFormatToSqlServer(string typeName)
{
var index = Array.IndexOf(CSharpTypes, typeName);
return index > -1
? SqlServerTypes[index]
: null;
}
Edit: fixed typo