Allgemein Für Administratoren Für Architekten Für Entwickler Für Projektleiter Für Tester News Produkte Publikationen
X
Jan Mattner

Jan Mattner

Patch for Entity Framework models based on Oracle databases

Montag, 02. Juni 2014

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.

Verwandte Artikel:

Benötigen Sie Unterstützung bei der Software-Entwicklung und Architektur von .NET basierten Lösungen oder bei Einführung und Anpassung von Visual Studio / Microsoft Test Manager / Team Foundation Server?

Wir stehen Ihnen unter info(at)aitgmbh.de gerne zur Verfügung.

Tags: , , , , ,

Hinterlasse eine Antwort