PostgreSQL to .NET type mapping

本文详细介绍了PostgreSQL数据库中的数据类型与.NET框架中对应类型的映射规则。这些规则适用于使用Visual Studio 2008-2015中的Entity Data Model Wizard或Entity Developer中的Create Model Wizard从数据库生成模型。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

PostgreSQL to .NET type mapping

Type mapping rules from this table are used when generating a model from a database with Entity Data Model Wizard in Visual Studio 2008 - 2015 and Create Model Wizard in Entity Developer.

PostgreSQL data types

SSDL1

CSDL1

.NET

boolean boolean Boolean System.Boolean
smallint, int2 smallint Int16 System.Int16
integer, int4 int Int32 System.Int32
bigint, int8 bigint Int64 System.Int64
real real Single System.Single
double precision, money double precision Double System.Double
numeric, decimal, float numeric, decimal, float Decimal System.Decimal
date, timestamp, timestamp with time zone, timestamp without time zone date, timestamp, timestamptz DateTime System.DateTime
time, time with time zone, time without time zone, interval time, timetz, interval Time System.TimeSpan
timestamp with time zone datetimeoffset DateTimeOffset System.DateTimeOffset
char, varchar, text, citext, enum, bit, varbit, cidr, inet, macaddr, point, line, lseg, box, path, polygon, circle, xml*, character, character varying, bit varying, json, jsonb char, varchar, text, enum, bit, varbit, cidr, inet, macaddr, point, line, lseg, box, path, polygon, circle, xml, json, jsonb String System.String
bytea bytea Binary System.Byte[]
uuid2 uuid Guid System.Guid
geometry3 spatial_geometry Geometry, GeometryCollection, GeometryLineString, GeometryMultiLineString, GeometryMultiPoint, GeometryMultiPolygon, GeometryPoint, GeometryPolygon System.Data.Spatial.DbGeometry
geography3 spatial_geography Geography, GeographyCollection, GeographyLineString, GeographyMultiLineString, GeographyMultiPoint, GeographyMultiPolygon, GeographyPoint, GeographyPolygon System.Data.Spatial.DbGeography

1 Note that when mapping corresponding database data type, you will need the .NET type with larger precision. That is because, for example, any Int32 value can be stored in the NUMBER(10) column, but largest NUMBER(10) column value cannot be stored in the Int32 field, it requires Int64 field.

2 Uuid and xml data types appeared in PostgreSQL 8.3.

3 Supported in Entity Framework v5 and v6.

.NET to PostgreSQL default type mapping

.NET

CSDL1

SSDL1

PostgreSQL data types

System.Boolean Boolean boolean boolean
System.Byte Byte byte smallint
System.Byte[] Binary bytea bytea
System.Data.Spatial.DbGeometry2 Geometry spatial_geometry geometry
System.Data.Spatial.DbGeography2 Geography spatial_geography geography
System.DateTime DateTime timestamp timestamp
System.DateTimeOffset DateTimeOffset datetimeoffset timestamp with time zone
System.Decimal Decimal numeric numeric
System.Double Double double precision double precision
System.Guid Guid uuid uuid
System.Int16 Int16 smallint smallint
System.Int32 Int32 int integer
System.Int64 Int64 bigint bigint
System.SByte SByte sbyte smallint
System.Single Single real real
System.String String char, varchar char, varchar
System.TimeSpan Time timestamp timestamp

1 Note that when mapping corresponding database data type, you will need the .NET type with larger precision. That is because, for example, any Int32 value can be stored in the NUMBER(10) column, but largest NUMBER(10) column value cannot be stored in the Int32 field, it requires Int64 field.

2 Supported in Entity Framework v5 and v6.

DateTimeOffcet type is not supported.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值