কেহ সি / সি এবং এসকিউএল সার্ভার ফর্ম্যাটগুলিতে রূপান্তর করার জন্য পদ্ধতিগুলির সন্ধান করছে, এখানে একটি সাধারণ বাস্তবায়ন চলে:
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;
}
সম্পাদনা: নির্দিষ্ট টাইপ