DB2 does not provide a dedicated type for storing boolean values in tables. There are different workarounds for this problem. The most common workarounds are using SMALLINT or CHAR(1) columns for storing boolean values and setting them to 0 or 1 for SMALLINT fields or to 'Y' or 'N' for CHAR(1) fields.
dotConnect for DB2 Entity Framework provider supports both mapping SMALLINT and CHAR(1) to System.Boolean. To support mapping System.Boolean to CHAR(1), a new data type "yes no char as boolean" is introduced. This type does not have a direct counterpart in DB2. It can be used in SSDL model part for columns of storage entities and as a column data types for Code First mapping. By default, mapping SMALLINT to System.Boolean is used. You can read about mapping CHAR(1) to System.Boolean for different development approaches below.EDM Wizard / EDM Designer
After creating an Entity Framework model, you need to edit it in the following way:
Entity Developer
If you need to map all the CHAR(1) columns to System.Boolean, add the new type mapping rule (on the Server Options -> DB2 page of Entity Developer Options dialog box) and then create the model. See the Creating and Editing Type Mapping Rules topic in the Entity Developer documentation.
If you need only some of the CHAR(1) columns to be mapped to System.Boolean, you need to manually edit the necessary properties and change their type from String to Boolean. You also need to change the type of the corresponding storage model columns from "CHAR" to "yes no char as boolean". Entity Developer allows doing it quite easily because it supports full-featured visual editing of both conceptual and storage parts of the model and quick navigation between conceptual model entity property and storage model entity column in two ways:
Defining Type Explicitly
The following example demonstrates mapping System.Boolean to both SMALLINT (the NumberBasedBoolean property) and CHAR(1) (the CharBasedBoolean property).
We will use the Column data annotation attribute to specify the type "yes no char as boolean":
The following DDL will be generated for such a class:
CREATE TABLE "BoolTables" ( "Id" INTEGER NOT NULL, "NumberBasedBoolean" SMALLINT NOT NULL, "CharBasedBoolean" CHAR(1) NOT NULL, PRIMARY KEY ("Id") )
Entity Framework 6 allows using conventions for mapping.
Conventions are convenient when, for example, all the System.Boolean properties in all model classes must be mapped to CHAR(1) columns. In such a case you may write a lightweight convention instead of specifying data type for each boolean property with ColumnAttribute.