Using Entity Framework with Oracle Pseudo Release

I am studying using Entity Framework in my organization. We use the Oracle DBMS, and therefore (for good or bad) use the "pseudo-logical" pattern common in Oracle, where instead of the Boolean column (which is not in Oracle) you have a column with 1 character with a check to force it to "Y" or "N".

So, if I want the object in my EF model to have the boolean property, how do I match this with the database column as “Y” for true and “N” for false? Is there a concept for “Converters” or something in the Entity Framework that will do this for me?

And just because it is likely to come, I know that EF only works with SQL Server. I would use DevArt dotConnect for Oracle to use EF with Oracle.
http://www.devart.com/dotconnect/oracle/

Edit
What about other ORM structures like NHibernate? Do they handle this out of the box scenario?

+4
source share
2 answers

Devart dotConnect for Oracle has an automatic mapping of the NUMBER (1) column to System.Boolean, simplifies the work with these columns - 0 corresponds to false, non-zero (default 1) - true. No further action is required.

If you want to store booleans in char form, then you need to choose one of the following methods:
1. Leave the row type for the property associated with the character column. Add an additional property of the shell of type boolean to the class of an incomplete entity and convert the string value to a logical one and vice versa to getter and setter respectively.
Disadvantage : this shell property cannot be used in LINQ for entities.
2. Create a view from your table that will return 0 or 1 instead of the values ​​from the character column. Alternatively, create DefiningQuery in the model for this EntitySet (in this case, it should not be added to the database). In most cases, you will need to change the property type from "char (1)" to "bool" in SSDL and from System.String to System.Boolean in CSDL. You must write a set of stored procedures to perform CUD operations with your entity and map these procedures to update this object.
Disadvantage : A lot of work.

+3
source

With the repeated absence of an official EDM-EF mapping from Oracle, DevArt and DataDirect have custom Oracle connection provider levels that you can buy. There are also open source versions in CodeProject that implement EDM for EF w / Oracle. I assume that you are using one of them.

To solve your question, you need to change the ProviderManifest implementation to return the corresponding .NET type when calling GetEdmType() . The problem is that this method passes you an Oracle type and expects you to return a .NET type that understands EF (it understands all primitives, including bool). Unfortunately, it is not advisable to display CHAR(1) in Boolean, since in principle you can use other CHAR(1) columns that are not bools.

A workaround to this problem is to create a user-defined type (JKBOOL, say :) that maps to CHAR(1) - you will have to change the tables to change CHAR(1) to JKBOOL . Now you can safely map JKBOOL to System.Boolean in GetEdmType() .

+1
source

Source: https://habr.com/ru/post/1309118/


All Articles