C# 数据类型映射 (SQLite,MySQL,MSSQL,Oracle)
MSSQL
SQLITE
一、C# vs SQLite:
C# | SQLite | ||||
字段名 | 类型 | 库类型 | GetFieldType(#) | 转换 | 备注 |
F_BOOL | bool | BIT NOT NULL | Boolean | ||
F_BOOL_NULL | bool? | BIT | Boolean | ||
F_SBYTE | sbyte | INT8 NOT NULL | SByte | sbyte_ | |
F_SBYTE_NULL | sbyte? | INT8 | SByte | sbyte_ | |
F_BYTE | byte | UINT8 NOT NULL | Byte | ||
F_BYTE_NULL | byte? | UINT8 | Byte | ||
F_SHORT | short | INT16 NOT NULL | Int16 | ||
F_SHORT_NULL | short? | INT16 | Int16 | ||
F_USHORT | ushort | UINT16 NOT NULL | UInt16 | ushort_ | |
F_USHORT_NULL | ushort? | UINT16 | UInt16 | ushort_ | |
F_INT | int | INT32 NOT NULL | Int32 | ||
F_INT_NULL | int? | INT32 | Int32 | ||
F_UINT | uint | UINT32 NOT NULL | UInt32 | uint_ | |
F_UINT_NULL | uint? | UINT32 | UInt32 | uint_ | |
F_LONG | long | INT64 NOT NULL | Int64 | ||
F_LONG_NULL | long? | INT64 | Int64 | ||
F_ULONG | ulong | UINT64 NOT NULL | UInt64 | ulong_ | |
F_ULONG_NULL | ulong? | UINT64 | UInt64 | ulong_ | |
F_FLOAT | float | FLOAT NOT NULL | Double | 不转兼容 | |
F_FLOAT_NULL | float? | FLOAT | Double | 不转兼容 | |
F_DOUBLE | double | DOUBLE NOT NULL | Double | ||
F_DOUBLE_NULL | double? | DOUBLE | Double | ||
F_DECIMAL | decimal | DECIMAL NOT NULL | Decimal | 存取不一:<F_DECIMAL>: [-79228162514264300000000000000] != [-79228162514264337593543950335] | |
F_DECIMAL_NULL | decimal? | DECIMAL | Decimal | 存取不一:<F_DECIMAL>: [-79228162514264300000000000000] != [-79228162514264337593543950335] | |
F_CHAR | char | TEXT NOT NULL | String | ||
F_CHAR_NULL | char? | TEXT | String | ||
F_STRING | string | TEXT NOT NULL | String | ||
F_STRING_NULL | string | TEXT | String | ||
F_DATETIME | DateTime | TEXT NOT NULL | String | ||
F_DATETIME_NULL | DateTime? | TEXT | String | ||
二、 C# vs MySQL:
C# | MySQL | ||||
字段名 | 类型 | 库类型 | GetFieldType(#) | 转换 | 备注 |
F_BOOL | bool | BOOL NOT NULL | Boolean | ||
F_BOOL_NULL | bool? | BOOL NULL | Boolean | ||
F_SBYTE | sbyte | TINYINT NOT NULL | SByte | sbyte_ | |
F_SBYTE_NULL | sbyte? | TINYINT NULL | SByte | sbyte_ | |
F_BYTE | byte | TINYINT UNSIGNED NOT NULL | Byte | ||
F_BYTE_NULL | byte? | TINYINT UNSIGNED NULL | Byte | ||
F_SHORT | short | SMALLINT NOT NULL | Int16 | ||
F_SHORT_NULL | short? | SMALLINT NULL | Int16 | ||
F_USHORT | ushort | SMALLINT UNSIGNED NOT NULL | UInt16 | ushort_ | |
F_USHORT_NULL | ushort? | SMALLINT UNSIGNED NULL | UInt16 | ushort_ | |
F_INT | int | INT NOT NULL | Int32 | ||
F_INT_NULL | int? | INT NULL | Int32 | ||
F_UINT | uint | INT UNSIGNED NOT NULL | UInt32 | uint_ | |
F_UINT_NULL | uint? | INT UNSIGNED NULL | UInt32 | uint_ | |
F_LONG | long | BIGINT NOT NULL | Int64 | ||
F_LONG_NULL | long? | BIGINT NULL | Int64 | ||
F_ULONG | ulong | BIGINT UNSIGNED NOT NULL | UInt64 | ulong_ | |
F_ULONG_NULL | ulong? | BIGINT UNSIGNED NULL | UInt64 | ulong_ | |
F_FLOAT | float | FLOAT NOT NULL | Single | 极值溢出 | |
F_FLOAT_NULL | float? | FLOAT NULL | Single | 极值溢出 | |
F_DOUBLE | double | DOUBLE NOT NULL | Double | ||
F_DOUBLE_NULL | double? | DOUBLE NULL | Double | ||
F_DECIMAL | decimal | DECIMAL NOT NULL | Decimal | 极值溢出 | |
F_DECIMAL_NULL | decimal? | DECIMAL NULL | Decimal | 极值溢出 | |
F_CHAR | char | CHARACTER NOT NULL | String | 中文报错 | |
F_CHAR_NULL | char? | CHARACTER NULL | String | 中文报错 | |
F_STRING | string | VARCHAR(50) NOT NULL | String | ||
F_STRING_NULL | string | VARCHAR(50) NULL | String | ||
F_DATETIME | DateTime | DATETIME NOT NULL | DateTime | ||
F_DATETIME_NULL | DateTime? | DATETIME NULL | DateTime | ||
三、 C# vs MSSQL:
C# | MSSQL | ||||
字段名 | 类型 | 库类型 | GetFieldType(#) | 转换 | 备注 |
F_BOOL | bool | bit NOT NULL | Boolean | ||
F_BOOL_NULL | bool? | bit NULL | Boolean | ||
F_SBYTE | sbyte | smallint NOT NULL | Int16 | sbyte_short | |
F_SBYTE_NULL | sbyte? | smallint NULL | Int16 | sbyte_short | |
F_BYTE | byte | tinyint NOT NUL; | Byte | ||
F_BYTE_NULL | byte? | tinyint NULL | Byte | ||
F_SHORT | short | smallint NOT NULL | Int16 | ||
F_SHORT_NULL | short? | smallint NULL | Int16 | ||
F_USHORT | ushort | int NOT NULL | Int32 | ushort_int | |
F_USHORT_NULL | ushort? | int NULL | Int32 | ushort_int | |
F_INT | int | int NOT NULL | Int32 | ||
F_INT_NULL | int? | int NULL | Int32 | ||
F_UINT | uint | bigint NOT NULL | Int64 | uint_long | |
F_UINT_NULL | uint? | bigint NULL | Int64 | uint_long | |
F_LONG | long | bigint NOT NULL | Int64 | ||
F_LONG_NULL | long? | bigint NULL | Int64 | ||
F_ULONG | ulong | real NOT NULL | Single | ulong_float | |
F_ULONG_NULL | ulong? | real NULL | Single | ulong_float | |
F_FLOAT | float | real NOT NULL | Single | ||
F_FLOAT_NULL | float? | real NULL | Single | ||
F_DOUBLE | double | float NOT NULL | Double | ||
F_DOUBLE_NULL | double? | float NULL | Double | ||
F_DECIMAL | decimal | decimal NOT NULL | Decimal | 极值溢出 | |
F_DECIMAL_NULL | decimal? | decimal NULL | Decimal | 极值溢出 | |
F_CHAR | char | char(1) NOT NULL | String | ||
F_CHAR_NULL | char? | char(1) NULL | String | ||
F_STRING | string | varchar(50) NOT NULL | F_STRING: | ||
F_STRING_NULL | string | varchar(50) NULL | String | ||
F_DATETIME | DateTime | datetime NOT NULL | DateTime | 必须介于 1/1/1753 12:00:00 AM 和 12/31/9999 11:59:59 PM 之间。 | |
F_DATETIME_NULL | DateTime? | datetime NULL | DateTime | ||
四、C# vs Oracle:
C# | Oracle | ||||
字段名 | 类型 | 库类型 | GetFieldType(#) | 转换 | 备注 |
F_BOOL | bool | CHAR(1) NOT NULL | String | bool_string | |
F_BOOL_NULL | bool? | CHAR(1) | String | bool_string | |
F_SBYTE | sbyte | NUMBER(3) NOT NULL | Int16 | sbyte_short | |
F_SBYTE_NULL | sbyte? | NUMBER(3) | Int16 | sbyte_short | |
F_BYTE | byte | NUMBER(3) NOT NULL | Int16 | byte_short | |
F_BYTE_NULL | byte? | NUMBER(3) | Int16 | byte_short | |
F_SHORT | short | NUMBER(5) NOT NULL | Int32 | short_int | |
F_SHORT_NULL | short? | NUMBER(5) | Int32 | short_int | |
F_USHORT | ushort | NUMBER(5) NOT NULL | Int32 | ushort_int | |
F_USHORT_NULL | ushort? | NUMBER(5) | Int32 | ushort_int | |
F_INT | int | NUMBER(10) NOT NULL | Int64 | int_long | |
F_INT_NULL | int? | NUMBER(10) | Int64 | int_long | |
F_UINT | uint | NUMBER(10) NOT NULL | Int64 | uint_long | |
F_UINT_NULL | uint? | NUMBER(10) | Int64 | uint_long | |
F_LONG | long | NUMBER(19) NOT NULL | Decimal | long_decimal | |
F_LONG_NULL | long? | NUMBER(19) | Decimal | long_decimal | |
F_ULONG | ulong | NUMBER(19) NOT NULL | Decimal | ulong_decimal | |
F_ULONG_NULL | ulong? | NUMBER(19) | Decimal | ulong_decimal | |
F_FLOAT | float | BINARY_FLOAT NOT NULL | Single | ||
F_FLOAT_NULL | float? | BINARY_FLOAT | Single | ||
F_DOUBLE | double | BINARY_DOUBLE NOT NULL | Double | 极值溢出 | |
F_DOUBLE_NULL | double? | BINARY_DOUBLE | Double | 极值溢出 | |
F_DECIMAL | decimal | DECIMAL(33,3) NOT NULL | Decimal | ||
F_DECIMAL_NULL | decimal? | DECIMAL(33,3) | Decimal | ||
F_CHAR | char | CHAR(1) NOT NULL | String | ||
F_CHAR_NULL | char? | CHAR(1) | String | ||
F_STRING | string | VARCHAR(50) NOT NULL | String | 不允许空字符 | |
F_STRING_NULL | string | VARCHAR(50) | String | 不允许空字符 | |
F_DATETIME | DateTime | TIMESTAMP NOT NULL | DateTime | 大值读取报错 | |
F_DATETIME_NULL | DateTime? | TIMESTAMP | DateTime | 大值读取报错 | |
附、类型转换:
using System;
using System.Collections.Generic;
using System.Text;
namespace vJine.Core.ORM {
public class TypeConverter {
public class sbyte_ /*: IConverter<sbyte>*/ {
public static sbyte CONV_Q(object V) {
return (sbyte)V;
}
}
public class ushort_ /*: IConverter<ushort>*/ {
public static ushort CONV_Q(object V) {
return (ushort)V;
}
}
public class uint_ /*: IConverter<uint>*/ {
public static uint CONV_Q(object V) {
return (uint)V;
}
}
public class ulong_ /*: IConverter<ulong>*/ {
public static ulong CONV_Q(object V) {
return (ulong)V;
}
}
public class bool_string /*: IConverter<bool>*/ {
public static object CONV_I(object V) {
if ((bool)V == true) {
return "1";
} else {
return "0";
}
}
public static bool CONV_Q(object V) {
if ((string)V == "1") {
return true;
} else {
return false;
}
}
}
public class sbyte_short /*: IConverter<sbyte>*/ {
public static object CONV_I(object V) {
return Convert.ToInt16(V);
}
public static sbyte CONV_Q(object V) {
return Convert.ToSByte(V);
}
}
public class byte_short /*: IConverter<byte>*/ {
public static object CONV_I(object V) {
return Convert.ToInt16(V);
}
public static byte CONV_Q(object V) {
return Convert.ToByte(V);
}
}
public class short_int /*: IConverter<short>*/ {
public static object CONV_I(object V) {
return Convert.ToInt32(V);
}
public static short CONV_Q(object V) {
return Convert.ToInt16(V);
}
}
public class ushort_int /*: IConverter<ushort>*/ {
public static object CONV_I(object V, string Name) {
return Convert.ToInt32(V);
}
public static ushort CONV_Q(object V, string Name) {
return Convert.ToUInt16(V);
}
}
public class int_long /*: IConverter<int>*/ {
public static object CONV_I(object V) {
return Convert.ToInt64(V);
}
public static int CONV_Q(object V) {
return Convert.ToInt32(V);
}
}
public class uint_long /*: IConverter<uint>*/ {
public static object CONV_I(object V) {
return Convert.ToInt64(V);
}
public static uint CONV_Q(object V) {
return Convert.ToUInt32(V);
}
}
public class long_decimal /*: IConverter<long>*/ {