Page 1 of 2

Boolean property with Entity Framework

Posted: Thu 03 Apr 2008 11:09
by baretta
Hi,

since Oracle don't support Boolean columns in tables, one usually have to work around this issue and stick with 0/1/Y/N flags or a similar approach.

But in a Entity Framework conceptual model, i really want to map those columns to System.Boolean properties, since it just doesnt make sense to use char or byte at this level to represent a numeric or literal flag.

Is there a way to map a, say, Oracle integer column, to a .NET Boolean property?
If not, it would make a great feature of OraDirect.

Thanks

Posted: Fri 04 Apr 2008 12:26
by Alexey.mdr
Your suggestion is quite reasonable.
We'd likely stick to it after the release of Entity framework is available.

Posted: Thu 10 Apr 2008 16:53
by baretta
nice!!

Posted: Fri 11 Apr 2008 07:22
by Alexey.mdr
If you have any other suggestions feel free to post them here.
Your comments and recommendations are highly appreciated!

Posted: Fri 20 Jun 2008 16:57
by rick.casey
Alexey, do you have any pattern where we can use a Boolean type in a property in the CSDL file while implementing the OraDirect .NET Entity Provider?

Thanks
Rick.

Posted: Mon 23 Jun 2008 12:18
by Alexey.mdr
Hello Rick,

We expect a new build of OraDirect .NET in the nearest days.
There, all NUMBER(1,0) columns on the server will be mapped as Boolean types automatically.
Let me know if you would like to change the edmx file manually.

Regards,
Alexey.

Posted: Mon 23 Jun 2008 12:33
by Alexey.mdr
Just if you would like to test it now:

Code: Select all

 

 

Posted: Mon 23 Jun 2008 14:33
by rick.casey
Thank you sir, that is exactly what I was looking for.
Rick.

Posted: Mon 23 Jun 2008 18:19
by baretta
Wow, you guys provide great service!

Do you mean that this feature has been implemented now, or has it actually worked all the time?
Don't know which version we have at work, but will download new tomorrow.

IMO, this is really a big improvement.
It is so, because it allows us to create a truly conceptual model;
we do not need to "marshal" a natural boolean as an integer,
just because we know our "first" Entity consumer is using Oracle.
The vendor's constraints is not affecting the conceptual model.

Just missing support for enum columns now, but i guess Microsoft need to implement this first.


Thanks

Posted: Wed 25 Jun 2008 07:43
by anton.connect
Manual mapping of Boolean type has been implemented in last build.
In the coming build NUMBER(1,0) will be mapped to Boolean automatically.

Re: Boolean property with Entity Framework

Posted: Wed 27 Aug 2014 16:16
by azabluda
Hello,

According to this article http://www.devart.com/dotconnect/oracle ... olean.html
The most common workarounds are using NUMBER(1) or CHAR(1) columns for storing boolean values and setting them to 0 or 1 for NUMBER(1) fields or to 'Y' or 'N' for CHAR(1) fields
it is possible to map boolean values
  • true to 1 or 'Y'
  • false to 0 or 'N'
But how can I map booleans to anything else? In our legacy database we have true represented by -1, and false by 0 or NULL (depending on some index performance/space considerations).

Thanks,
Alexander

Re: Boolean property with Entity Framework

Posted: Fri 29 Aug 2014 07:38
by Shalex
azabluda wrote:But how can I map booleans to anything else? In our legacy database we have true represented by -1, and false by 0 or NULL (depending on some index performance/space considerations).
The support of boolean properties, when the corresponding column is NUMBER(1, 0), was improved starting from the 8.4.215 build of dotConnect for Oracle (now it considers true represented by numbers <> 0): http://forums.devart.com/viewtopic.php?t=30011.

Re: Boolean property with Entity Framework

Posted: Fri 29 Aug 2014 10:02
by azabluda
Hello Shalex,

Thank you for the swift reply!

The topic you've provided is mainly discussing the building of WHERE-conditions for SELECTs. This is of course also very important but first we need to activate the non-standard mapping for the INSERT and UPDATE commands.
  • A new entity Foo with boolean property X=true must be inserted into the database with FOO.X = -1 (the default behavior appears to insert 1)
  • A new entity Foo with boolean property X=false must be inserted into the database with FOO.X = NULL (the default behavior appears to insert 0)
  • For another boolean property Foo.Y of the same entity we need mapping to [-1, 0] instead of [-1, NULL]
Could you please send me a link to the documentation which explains how to configure the non-standard boolean mappings?

Thanks,
Alexander

Re: Boolean property with Entity Framework

Posted: Mon 01 Sep 2014 13:49
by Shalex
In this case, you should add a property-wrapper which would implement your logic like:

Code: Select all

private int? _MappedProperty;
private int MappedProperty{
        get 
        {
           return _MappedProperty; 
        }
        set 
        {
           _MappedProperty = value; 
        }
}
public bool UnMappedProperty{
        get 
        {
           if (MappedProperty == 0)
             return false 
           else
             return true
        }
        set 
        {
           if ((value == false) or (value == null))
             MappedProperty = 0
           else
             MappedProperty = 1
        }
}

Re: Boolean property with Entity Framework

Posted: Mon 01 Sep 2014 13:54
by azabluda
This is of course horrible, but thanks anyway.

I'm just wondering.. if you've managed to map boolean true => 'Y' in dotConnect, then how difficult would it be to provide a similar mapper for true => -1? May this eventually become a feature of a future version of dotConnect?