dotConnect for DB2 Documentation
Entity Framework Data Type Mapping
support@devart.com

DB2 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 - 2019 and Create Model Wizard in Entity Developer.

DB2 data types

SSDL1

CSDL1

.NET

SMALLINT smallint Int16 System.Int16
INTEGER integer Int32 System.Int32
BIGINT bigint Int64 System.Int64
REAL real Single System.Single
DOUBLE, FLOAT double, float Double System.Double
DECIMAL, NUMERIC, DECFLOAT decimal, numeric, decfloat Decimal System.Decimal
DATE, TIMESTAMP date, timestamp DateTime System.DateTime
TIME time Time System.TimeSpan
CHAR, VARCHAR, LONG VARCHAR2, CLOB, GRAPHIC, VARGRAPHIC, LONG VARGRAPHIC2, DBCLOB, XML, DATALINK char, varchar, long varchar, clob, graphic, vargraphic, long vargraphic, dbclob, xml, datalink String System.String
CHAR FOR BIT DATA, VARCHAR FOR BIT DATA, LONG VARCHAR FOR BIT DATA2, BLOB char for bit data, varchar for bit data, long varchar for bit data, blob Binary System.Byte[]

The following mapping is optional. In Entity Developer you may tweak type mapping rules before creating the model, while for EDM Wizard/LightSwitch you need to modify XML mapping code manually after generating a model.

DB2 data types

SSDL1

CSDL1

.NET

CHAR(1) yes no char as boolean Boolean System.Boolean
SMALLINT boolean Boolean System.Boolean
SMALLINT byte Byte System.Byte
SMALLINT sbyte SByte System.SByte
CHAR(16) FOR BIT DATA guid Guid System.Guid

.NET to DB2 default type mapping

.NET

CSDL1

SSDL1

DB2 data types

System.Boolean Boolean boolean SMALLINT
System.Byte Byte byte SMALLINT
System.Byte[] Binary char for bit data, varchar for bit data, blob3 CHAR FOR BIT DATA, VARCHAR FOR BIT DATA, BLOB3
System.DateTime DateTime timestamp TIMESTAMP
System.DateTimeOffset DateTimeOffset not supported4 not supported4
System.Decimal Decimal decimal DECIMAL
System.Double Double double DOUBLE
System.Guid Guid guid CHAR(16) FOR BIT DATA
System.Int16 Int16 smallint SMALLINT
System.Int32 Int32 integer INTEGER
System.Int64 Int64 bigint BIGINT
System.SByte SByte sbyte SMALLINT
System.Single Single real REAL
System.String String char, varchar, clob, graphic, vargraphic, dbclob5 CHAR, VARCHAR, CLOB, GRAPHIC, VARGRAPHIC, DBCLOB5
System.TimeSpan Time time TIME

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 IBM officially does not recommend to use LONG VARCHAR, LONG VARGRAPHIC and LONG VARCHAR FOR BIT DATA datatypes.

3 Mapping depends on MaxLength and FixedLength facets.

4 DB2 for LUW does not support a data type, which can store and process the System.DateTimeOffset type.

5 Mapping depends on MaxLength, FixedLength, and Unicode facets.

See Also

Entity Framework  | Using CHAR(1) mapped to System.Boolean in Entity Framework