Skip to content
This repository has been archived by the owner on Jul 13, 2018. It is now read-only.
JanMattner edited this page Nov 12, 2014 · 1 revision

What's this patch all about?

If you use the Entity Framework (EF) with Oracle databases, you probably stumbled over the following problem. The ID field of a new entry is not automatically incremented in the EF model and keeps its default value 0, although a correct trigger has been defined in the database.

This problem is rooted in the Oracle databases up to version 12.0. Since these databases do not know identity columns, the increment is not done automatically and a workaround using triggers is necessary. Thus the identity property is not part of the *.edmx model which is created by the entity framework.

The downside of this becomes apparent if one adds new entries using the EF and assumes that the ID is automatically incremented. Actually all new entries have the default value 0 – but only in the EF model, the original entries in the database have been correctly modified! If the column in the EF model had the identity property, the model would have checked the database again and applied the right ID value.

Obviously the problem can be solved by adding the identity property post hoc to all identity columns in the EF model. This adjustment can be conveniently done by using the AIT EF Oracle Identity Patch. The patch can be downloaded as NuGet package. During the installation of the package, an *.xml configuration file is automatically created, in which one can define the columns that should be modified. In each build process this patch ensures that all specified columns in the *.edmx file have the identity property. The model is adjusted if necessary. Using this patch you don’t have to worry about the auto increment anymore.

Customization

The configuration file is created in the project at /Config/AIT.EF.Oracle.IdentityPatch.xml and initially looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<IdentityRoot>
    <!-- Add identity entries here. Syntax:
    <EDMX Name="path_to_edmx_file_relative_to_project_folder_without_leading_backslash">
        <IdentityEntry Table="table_name" Column="column_name"/>
    </EDMX>
    -->
</IdentityRoot>

Thus if your project structure is as follows:

\MyProject.csproj
\Application\App.cs
\Config\AIT.EF.Oracle.IdentityPatch.xml
\Model\MyModel.edmx

You can add the identity property to the column "OrderId" in table "Order" and columns "OrderId" and "LineNumber" in table "OrderDetail" with the following configuration file:

<?xml version="1.0" encoding="utf-8" ?>
<IdentityRoot>
    <EDMX Name="Model\MyModel.edmx">
        <IdentityEntry Table="Order" Column="OrderId"/>
        <IdentityEntry Table="OrderDetail" Column="OrderId"/>
        <IdentityEntry Table="OrderDetail" Column="LineNumber"/>
    </EDMX>
</IdentityRoot>
Clone this wiki locally