Identifier Name Length and Uniqueness

Oracle Database prior to version 12.2 limit identifier names, such as table names, column names, and primary key names, to 30 characters. Oracle Database 12.2 and higher have a default limit of 128 characters.

In Entity Framework Core Migrations, these identifier lengths should be constrained to prevent creating identifier names longer than what the Oracle Database version supports. Attempting to create an identifier longer than the database can support generally results in an "ORA-00972: IDENTIFIER IS TOO LONG" error.

Use RelationalModelAnnotations MaxIdentifierLength property (EF Core 2.x) or ModelBuilder HasAnnotation method (EF Core 3.x) to set the maximum identifier length the target database version can handle. For example, if Oracle Database 12.1.0.2 is used, it needs to be set to 30 (or less). Once set, Entity Framework Core will automatically truncate identifier names that are too long to the specified length. This prevents both the user and Entity Framework Core from creating identifiers beyond the maximum character limit of the Oracle Database version you are connecting to.

// C# Sample Code: Setting maximum identifier length to 30 characters; By default, it's set to 128.
modelBuilder.Model.Relational().MaxIdentifierLength = 30;

Entity Framework Core 2.x has a known issue in which identifier names longer than the maximum identifier length are merely truncated, but not made unique. Also, the MaxIdentifierLength has no impact on controlling the length of table names that are created based on the entity class names. These issues have been resolved in Entity Framework Core 3.x.

In the meantime, either rename the class names, property names, etc. to work around this issue or use the ToTable()/HasColumnName() fluent APIs or their equivalent data annotations to specify a shorter and/or unique names for the tables/columns that are to be created in the Oracle database.

If the identifiers use multi-byte characters, the MaxIdentifierLength may need to be set with character expansion ratio in mind to assure that all identifiers can be created in the Oracle database. For example, if the Oracle database character set is UTF8, a single character may require up to 4 bytes. Thus, to guarantee that all identifiers can be created in an Oracle database that does not support long identifiers, the MaxIdentifierLength should be set to 7 characters (i.e. 30 characters divided by 4).

If your EF Core model does not use identifier names longer than what your database version supports, you should still set MaxIdentifierLength. ODP.NET and Entity Framework Core auto-generate schema object names from models. They may, on occasion, append additional characters to the names, which could exceed the maximum number of characters the database version permits. By setting the MaxIdentifierLength, you prevent EF Core from causing the ORA-00972 inadvertently.