Boolean property with Entity Framework

Boolean property with Entity Framework

Postby baretta » Thu 03 Apr 2008 11:09

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
baretta
 
Posts: 6
Joined: Thu 03 Apr 2008 10:44
Location: OSLO

Postby Alexey.mdr » Fri 04 Apr 2008 12:26

Your suggestion is quite reasonable.
We'd likely stick to it after the release of Entity framework is available.
Alexey.mdr
 
Posts: 729
Joined: Thu 13 Dec 2007 10:24

Postby baretta » Thu 10 Apr 2008 16:53

nice!!
baretta
 
Posts: 6
Joined: Thu 03 Apr 2008 10:44
Location: OSLO

Postby Alexey.mdr » Fri 11 Apr 2008 07:22

If you have any other suggestions feel free to post them here.
Your comments and recommendations are highly appreciated!
Alexey.mdr
 
Posts: 729
Joined: Thu 13 Dec 2007 10:24

Postby rick.casey » Fri 20 Jun 2008 16:57

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.
rick.casey
 
Posts: 5
Joined: Fri 20 Jun 2008 16:55

Postby Alexey.mdr » Mon 23 Jun 2008 12:18

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.
Alexey.mdr
 
Posts: 729
Joined: Thu 13 Dec 2007 10:24

Postby Alexey.mdr » Mon 23 Jun 2008 12:33

Just if you would like to test it now:
Code: Select all



Alexey.mdr
 
Posts: 729
Joined: Thu 13 Dec 2007 10:24

Postby rick.casey » Mon 23 Jun 2008 14:33

Thank you sir, that is exactly what I was looking for.
Rick.
rick.casey
 
Posts: 5
Joined: Fri 20 Jun 2008 16:55

Postby baretta » Mon 23 Jun 2008 18:19

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
baretta
 
Posts: 6
Joined: Thu 03 Apr 2008 10:44
Location: OSLO

Postby anton.connect » Wed 25 Jun 2008 07:43

Manual mapping of Boolean type has been implemented in last build.
In the coming build NUMBER(1,0) will be mapped to Boolean automatically.
anton.connect
 
Posts: 43
Joined: Thu 19 Jun 2008 14:30

Re: Boolean property with Entity Framework

Postby azabluda » Wed 27 Aug 2014 16:16

Hello,

According to this article http://www.devart.com/dotconnect/oracle/docs/CharAsBoolean.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
azabluda
 
Posts: 34
Joined: Thu 10 Sep 2009 14:45

Re: Boolean property with Entity Framework

Postby Shalex » Fri 29 Aug 2014 07:38

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.
Shalex
Devart Team
 
Posts: 7839
Joined: Thu 14 Aug 2008 12:44

Re: Boolean property with Entity Framework

Postby azabluda » Fri 29 Aug 2014 10:02

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
azabluda
 
Posts: 34
Joined: Thu 10 Sep 2009 14:45

Re: Boolean property with Entity Framework

Postby Shalex » Mon 01 Sep 2014 13:49

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
        }
}
Shalex
Devart Team
 
Posts: 7839
Joined: Thu 14 Aug 2008 12:44

Re: Boolean property with Entity Framework

Postby azabluda » Mon 01 Sep 2014 13:54

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?
Last edited by azabluda on Tue 02 Sep 2014 14:34, edited 1 time in total.
azabluda
 
Posts: 34
Joined: Thu 10 Sep 2009 14:45

Next

Return to dotConnect for Oracle