Entity Framework, fluent api and trouble when mapping Boolean type to byteint Teradata database type

Connectivity
Fan

Entity Framework, fluent api and trouble when mapping Boolean type to byteint Teradata database type

How can I map Boolean type using Entity Framework, Fluent Api?

I found this in Teradata type mapping documentation

"

Teradata does not natively support a Boolean type.

SSDL must be manually modified to enable Teradata ByteInt to Boolean Type mapping. Precision Facet must be set 1 as shown below:

Boolean Entity Type Mapping     Copy Code

<EntityType Name="BooleanDataType">

     <Key>

          <PropertyRef Name="C01_INTEGER" />

     </Key>

     <Property Name="C2_BOOLEAN" Type="byteint" Precision="1"/>

</EntityType>

.NET Entity Provider will map numeric value 1 to true and numeric value 0 to false.

"

But how convert this SSDL mapping to Fluent Api mapping, when "PrimitivePropertyConfiguration" have not  a "hasPrecision()" method?

When I only doing

            this.Property(t => t.allow_notification).HasColumnName("allow_notification");

            this.Property(t => t.allow_notification).HasColumnType("byteint");

I got error

"Schema specified is not valid. Errors: (54,12) : error 2019: Member Mapping specified is not valid. The type 'Edm.Boolean[Nullable=False,DefaultValue=]' of member 'allow_notification' in type 'PZKBSlowniki.Models.DTO_dictionaries' is not compatible with 'Teradata.byteint[Nullable=False,DefaultValue=,Precision=3]' of member 'allow_notification' in type 'CodeFirstDatabaseSchema.DTO_dictionaries'."

1 REPLY
Fan

Re: Entity Framework, fluent api and trouble when mapping Boolean type to byteint Teradata database type

Does realy no one know answer?

For now i done this my way.

In Teradata I make BYTEINT data type field

CREATE TABLE D3_GRP_DCT.dictionaries

(

id INTEGER NOT NULL generated by default as identity,

allow_create BYTEINT TITLE 'create (INSERT) dodanie rekordu do słownika' default 0,

PRIMARY KEY (id)

);

In .NET, DataAnnotations class loks like similar to this one.

public class DTO_dictionaries

{

        [Key]

        public int id {get;set;}

        public System.Int16 active {get;set;}

        [NotMapped]

        public Boolean bactive

        {

            get { return active == 1; }

            set { active = value == true ? (short)1 : (short)0; }

        }

}

As you can see I annotated property "active" as System.Int16, but I also add "bactive" property which have [NotMapped] attribute. Of course in application code you have to use only "bactive" property. Unfortunately "active" property also have to be "public".

I realize that this is not the best solution, if somone known better one I still expect answer.