Boolean property with Entity Framework
Boolean property with Entity Framework
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
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
-
- Posts: 729
- Joined: Thu 13 Dec 2007 10:24
-
- Posts: 729
- Joined: Thu 13 Dec 2007 10:24
-
- Posts: 5
- Joined: Fri 20 Jun 2008 16:55
-
- Posts: 729
- Joined: Thu 13 Dec 2007 10:24
-
- Posts: 729
- Joined: Thu 13 Dec 2007 10:24
Just if you would like to test it now:
Code: Select all
-
- Posts: 5
- Joined: Fri 20 Jun 2008 16:55
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
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
-
- Posts: 43
- Joined: Thu 19 Jun 2008 14:30
Re: Boolean property with Entity Framework
Hello,
According to this article http://www.devart.com/dotconnect/oracle ... olean.html
Thanks,
Alexander
According to this article http://www.devart.com/dotconnect/oracle ... olean.html
it is possible to map boolean valuesThe 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
- true to 1 or 'Y'
- false to 0 or 'N'
Thanks,
Alexander
Re: Boolean property with Entity Framework
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.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).
Re: Boolean property with Entity Framework
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.
Thanks,
Alexander
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]
Thanks,
Alexander
Re: Boolean property with Entity Framework
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
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?
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.