Hi there! Hopefully, you've come for one or more of my pearls of wisdom, or at least a good laugh :)

Hit the main page for the latest from me, or the archives for the older (but not necessarily better) stuff.

Saturday, 26 May 2012

Entity Framework 4, Oracle and Booleans...

I'd been having three days of trauma at work, but finally the sun shone through!

My team have been tasked with (re-)implementing Oracle database support in our application. We'd been working on the changes needed in the guts of the app for a few months, and had gotten to the point where all our unit tests worked fine against the code and database.

Next step was beta preparation, so we needed to make sure the product still deployed OK. Which it doesn't.

Our product makes use of Entity Framework 4 to simplify the DAL code, so needs the Oracle Data Provider for .NET (ODP.NET), part of Oracle Data Access Client 11.2 Release 4, to operate against an Oracle database.

The problem is that our team, like many others that use ODP.NET, don't want to force the entire ODP.NET installation on our customers since it's a tad on the obese side. We worked out precisely which DLLs we needed from the distribution and intend to supply just them with the product to make it as small as possible. Now, that not a bad thing normally, but...

Our product's databases, having originally been designed against Microsoft SQL Server, feature the BIT data-type quite heavily, equivalent to the Boolean data-type in C#. Oracle databases don't have a native data-type that equates, so we decided to make use of Entity Framework's data model mapping feature, and define an override such that a C# Boolean would be seen as a NUMBER(1,0) in Oracle and vice versa. Now, we worked that out months back and everything had been going fine with our automated tests and development. But...

When I was trying to deploy the software "for real", I kept bumping into this error when trying to get past the database installation part of our installer:
Error 2019: Member Mapping specified is not valid.

But the mapping was there in the App.Config file for the installer! What the...! After two days of head-meets-desk, I decided that the only way forward would be to try and understand what Oracle's code was attempting to do. (Cue shameless product plug...)

I used Telerik's JustDecompile to look inside the Oracle.DataAccess.dll file (sorry Oracle, but it was the only way) and found that if you didn't have the right 32-bit Registry Key, namely "HKLM\Software\Oracle\ODP.NET\", then the Oracle.DataAccess code would completely ignore the App.Config's override settings, causing my problem!

One quick tweak later, and hey presto, our product installed OK at last! Admittedly, I soon ran into something else, but at least we got another step forward :)