Fork me on GitHub

CSRobot gen:mysql,pg-c#类型映射

  下面的数据库类型和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(sized)

float

FLOAT(p)

float

DOUBLE(sized)

double

DOUBLE PRECISION(sized)

double

DECIMAL(sized)

decimal

DEC(sized)

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  [ (ps) ], decimal [ (ps) ]

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

  
  想要更快更方便的了解相关知识,可以关注微信公众号 
 

 

 

posted @ 2022-02-04 09:11  桂素伟  阅读(73)  评论(0编辑  收藏  举报