下面的数据库类型和c#类型的映射关系,只是我个人的想法,应该不同的业务场景对应可能不一样,比如json,xml,line,polygon结构化的数据,如果在C#中有对应的实体类,可以很友好的转换,如果没有,可以用现有的类型存储,再作转换,比如json,xml都可以用string来接收。
mysql字段类型和c#类型对应
| Data type | C# | 
| CHAR(size) | string | 
| VARCHAR(size) | string | 
| BINARY(size) | byte[],object | 
| VARBINARY(size) | byte[],object | 
| TINYBLOB | btye[],object | 
| TINYTEXT | string | 
| TEXT(size) | string | 
| BLOB(size) | byte[],object | 
| MEDIUMTEXT | string | 
| MEDIUMBLOB | byte[],object | 
| LONGTEXT | string | 
| LONGBLOB | byte[],object | 
| ENUM(val1, val2, val3, ...) | string | 
| SET(val1, val2, val3, ...) | object | 
| BIT(size) | bit | 
| TINYINT(size) | byte | 
| BOOL | bool | 
| BOOLEAN | bool | 
| SMALLINT(size) | short | 
| MEDIUMINT(size) | short | 
| INT(size) | int32 | 
| INTEGER(size) | int32 | 
| BIGINT(size) | long | 
| FLOAT(size, d) | float | 
| FLOAT(p) | float | 
| DOUBLE(size, d) | double | 
| DOUBLE PRECISION(size, d) | double | 
| DECIMAL(size, d) | decimal | 
| DEC(size, d) | decimal | 
| DATE | DateTime | 
| DATETIME(fsp) | DateTime | 
| TIMESTAMP(fsp) | DateTime | 
| TIME(fsp) | DateTime | 
| YEAR | short | 
postgres字段类型和c#类型对应关系
| Name | C# | 
| Bigint, int8 | long | 
| Bigserial, serial8 | long | 
| bit [ (n) ] | bit[] | 
| bit varying [ (n) ], varbit [ (n) ] | bit[] | 
| Boolean, bool | bool | 
| box | object | 
| bytea | byte[] | 
| character [ (n) ], char [ (n) ] | string | 
| character varying [ (n) ], varchar [ (n) ] | string | 
| cidr | object | 
| circle | object | 
| date | DateTime | 
| double precision, float8 | double | 
| inet | object | 
| Integer, int, int4 | int | 
| interval [ fields ] [ (p) ] | string | 
| json | string | 
| jsonb | string | 
| line | object | 
| lseg | object | 
| macaddr | object | 
| macaddr8 | object | 
| money | Decimal | 
| numeric [ (p, s) ], decimal [ (p, s) ] | decimal | 
| path | object | 
| pg_lsn | object | 
| pg_snapshot | object | 
| point | object | 
| polygon | object | 
| Real, float4 | float | 
| Smallint, int2 | Short | 
| Smallserial, serial2 | short | 
| Serial, serial4 | int | 
| text | string | 
| time [ (p) ] [ without time zone ] | DateTime | 
| time [ (p) ] with time zone, timetz | DateTimeOffset | 
| timestamp [ (p) ] [ without time zone ] | DateTime | 
| timestamp [ (p) ] with time zone, timestamptz | DateTimeOffset | 
| tsquery | object | 
| tsvector | object | 
| txid_snapshot | object | 
| uuid | GUID | 
| xml | string |