Boolean and MsAccess

Posts   
 
    
Valemus avatar
Valemus
User
Posts: 37
Joined: 09-Jan-2018
# Posted on: 07-Mar-2018 14:32:54   

Hi! I'm using C#, Model-first, Adapter, MsAccess driver. When I try to read some data from the database which contains Booleans I get an error of "invalid cast" inside the generated code of the Entity.

Example:


    public virtual System.Boolean myBooleanField
        {
            get { return (System.Boolean)GetValue((int)myEntityFieldIndex.myBooleanField, true); } // <-- Error
            set { SetValue((int)myEntityFieldIndex.myBooleanField, value); }
        }

Is there any known issue using the Boolean type in MsAccess?

Thanks!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 07-Mar-2018 15:00:41   

Is the field also a boolean field? What is the type of the field the MyBooleanField is mapped on? (btw ms access and model first... be careful you define the right types as there's no DDL SQL generated for ms access. better do database first with ms access)

Frans Bouma | Lead developer LLBLGen Pro
Valemus avatar
Valemus
User
Posts: 37
Joined: 09-Jan-2018
# Posted on: 07-Mar-2018 15:17:06   

Otis wrote:

Is the field also a boolean field? What is the type of the field the MyBooleanField is mapped on?

System.Boolean, automatically mapped to DbType YesNo.

(btw ms access and model first... be careful you define the right types as there's no DDL SQL generated for ms access. better do database first with ms access)

The problem is that MsAccess is not the only one database that I need to support disappointed

Valemus avatar
Valemus
User
Posts: 37
Joined: 09-Jan-2018
# Posted on: 07-Mar-2018 15:26:44   

Ok, I think I have to change them to use the Converter BooleanNumericConverter and Byte...

simple_smile

However I notice that the automatic field creation is proposing a not-working mapping.

Valemus avatar
Valemus
User
Posts: 37
Joined: 09-Jan-2018
# Posted on: 07-Mar-2018 15:31:51   

Valemus wrote:

Ok, I think I have to change them to use the Converter BooleanNumericConverter and Byte...

simple_smile

However I notice that the automatic field creation is proposing a not-working mapping.

No, wait... I've seen what happened... it's all my fault. Blame me flushed I generated the Sql Server DB and created the MsAccess out of that. In this conversione the Bool was converted into Number, not YesNo. So.. no, don't blame me but Sql Server Tools smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 07-Mar-2018 15:40:08   

Always those pesky sqlserver tools! wink Glad it's sorted

Frans Bouma | Lead developer LLBLGen Pro