Problem setting TruncateLongDefaultNames

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
hfj
Posts: 3
Joined: Tue 22 Jan 2013 14:01

Problem setting TruncateLongDefaultNames

Post by hfj » Tue 22 Jan 2013 14:20

Hello, I am trying to do a code-first migration against an oracle database using dotConnect for oracle.

Some indexes are composed of many columns and the generated name becomes something like:IX_ProductID_VersionLevel1_xxxxxxxxxxx_yyyyyyyyyyy_zzzzzzzzzzzzzzzzzz

This gives of course an error about the index name length being too long, because of ORacle 30 char limit, when running Update-Database from package manager console.

I found the option

Code: Select all

CodeFirstOptions.TruncateLongDefaultNames = true;
Which I thought would truncate the long names.

So in the static constructor of my class inheriting from DbContext i put:

Code: Select all

OracleEntityProviderConfig.Instance.CodeFirstOptions.TruncateLongDefaultNames = true;
This had little effect.

Just for kicks, I tried setting the option:

Code: Select all

CodeFirstOptions.AddTableNameInDefaultIndexName = false;
true/false and then I saw that this value actually was taken into account, because another error message occured (something that was too long passed when turned off)

I then tried setting this options in the App.config of my DbContext project (using it as startup project for code first migration)

I added the configsection:

Code: Select all

<section name="Devart.Data.Oracle.Entity" type="Devart.Data.Oracle.Entity.Configuration.OracleEntityProviderConfigurationSection, Devart.Data.Oracle.Entity, Version=7.5.164.0, Culture=neutral, PublicKeyToken=09af7300eec23701" />
And the following config:

Code: Select all

<Devart.Data.Oracle.Entity xmlns="http://devart.com/schemas/Devart.Data.Oracle.Entity/1.0">
    <CodeFirstOptions TruncateLongDefaultNames="true" AddTableNameInDefaultIndexName="false"/>
  </Devart.Data.Oracle.Entity>
I then saw the same behavior, the AddTableNameInDefaultIndexName worked, but the TruncateLongDefaultNames had little effect.

Am I doing something wrong?

hfj
Posts: 3
Joined: Tue 22 Jan 2013 14:01

Re: Problem setting TruncateLongDefaultNames

Post by hfj » Wed 23 Jan 2013 11:16

I figured it out, by reading the documentation fully =)

I expected it to also truncate long column names, when I turned on trucating, the Index length error message disappeared, but some views were having column names longer than 30 chars and I mistook this to be the same error.

As it stands, my post is an example on how to use the TruncateLongDefaultNames and other CodeFirstOptions.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Problem setting TruncateLongDefaultNames

Post by Shalex » Mon 28 Jan 2013 11:17

Additional recommendations:
  • user-defined columns/tables names can be set via Column/Table attributes (consequently you may control the length of the names in this way)
  • you can migrate to EF6 Alpha 2, which supports custom conventions, and create your own convention to name objects (classes, properties) in a correct way

Post Reply