Reputation: 442
So... I downloaded and installed Oracle's Beta version of their EF provider... Why? Because nothing else seemed to work very well (i tried the one on CodePlex as well as the one on MSDN), and my company is not going to pay for a commercially available one (like the one from devart).
So, it worked great. I was able to see the oracle database, select the particular schema I was interested in, pull in the table definitions. Great!
Now I get an error. It seems the default behavior of the provider is to map number(1,0) fields to boolean types in .NET. Not good, but, I should be able to change this, right? The error I got was something along the lines of "the types don't match". So I change the definition of that field to a Decimal(1,0).
Now, the new error I am getting is that decimal(1,0) is not compatible with number(1,0). And I am stuck. I cannot make a change to the mapping to anything that works.
I don't like using Oracle to begin with because they seem to be a couple of years behind supporting anything .NET related. Now, I am ready to give up on them altogether.
So, my question is this... I this any way besides the devart components that I can get Oracle working with EF? It would make my life simpler if I can. If not, then I get to hand-code all of this goodness... or tell the partner to switch over to SQL server since it's just as good (for what they are doing with it...)
Upvotes: 3
Views: 1069
Reputation: 1205
Few days back in my last project i worked on Oracle 11g and ODAC beta vresion for EF4. I came across many problems regarding its use like no function can access, Working with Stored Prodedure is great and easy until you are not returning any value from it then you have to use RefCusrose, In Views you must have to give primary key and the one that you are saying mapping number(1,0) fields to Boolean and and most of the fields maps in Decimal format.
I found Oracle forum is very useful here on oracle form people gave three suggestions to solve it i am as it is quoting it all..
1. In .Config files set alterntives
In ODAC EF Beta 2, by default, Number(1, 0) will be mapped to Edm.Int16. You may specify in the app.config or web.config to map Number(1, 0) to Edm.Boolean instead.
The following info applies to the upcoming Beta 2:
The default mapping for Oracle NUMBER(p, 0) types can be overridden based on a custom mapping that can be configured in a app.config, web.config, or a machine.config.
For example, by default NUMBER(1, 0) is mapped to Int16. However, users may want to map NUMBER(1, 0) to .NET Bool or .NET Byte type. This can be done via a configuration file.
Below is an example of app.config that contains a custom mapping where NUMBER(1, 0) is mapped to Bool, NUMBER(3,0) is mapped to Byte, and the maximum precisions for Int16, Int32, Int64 are changed to 4, 9, 18 from the default values of 5, 10, 19, respectively:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
</connectionStrings>
<oracle.dataaccess.client>
<settings>
<add name="bool" value="edmmapping number(1,0)" />
<add name="byte" value="edmmapping number(3,0)" />
<add name="int16" value="edmmapping number(4,0)" />
<add name="int32" value="edmmapping number(9,0)" />
<add name="int64" value="edmmapping number(18,0)" />
</settings>
</oracle.dataaccess.client>
</configuration>
2. Static class For Conversion:
namespace convert{
static class boolConvert
{
public static bool boolchar(char ON)
{
switch (ON)
{
case 'O':
return true;
case 'N':
return false;
default:
return true;
}
}
public static char charbool(bool ON)
{
switch (ON)
{
case true:
return 'O';
case false:
return 'N';
default:
return 'O';
}
}
}
}
then you could use it to do you conversions where required: bool isSomthing = convert.boolConvert.boolchar('N'); char isSomthigEelse = convert.boolConvert.charbool(true);
3. Use Property If you are using POCO's
If you're using one of the code generators that generates POCOs you could add a property in a partial class. If you have a field called "MyField", then in the partial class add something like this:
public bool MyField_Boolean
{
get
{
return MyField == 'O';
}
}
You won't be able to use MyField_Boolean inside an EF Linq query (because it's not a database property) but anywhere else in your code you can use it instead to get a boolean version.
Although i didn't tested any of them yet but may be it'll solve your problem. I am hoping that the next version of ODAC wont have these kinda issues.
Upvotes: 0
Reputation: 5081
This sounds like beta 1. By default beta 1 mapped number(1,0) to boolean and all other number types to decimal.
Beta 2 is out now and should fix both of these issues. Beta 2 lets you choose what to map Number(1,0) to and also supports mapping to more sane things like int and long when you're using a number(X,0). Full info is in the readme, but the short version is that the fastest way to get what you want is to install beta 2, then delete and recreate your model. (You can update it, but it's a bit of a hassle from beta 1 due to so much stuff changing and it sounds like you didn't get very far.)
In my experience with beta 2, it should get the types right a lot more often then beta 1 did. So you shouldn't have change nearly as much.
Upvotes: 1
Reputation: 122002
Try to open the model in XML Editor, change the property type to a number with the precision of 2 in the SSDL part of the model, and change the property type to Decimal with precision of 2 in the CSDL part of the model.
Upvotes: 1