New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL-Server : EF Generates too long index name #10213

Closed
cdie opened this Issue Nov 3, 2017 · 2 comments

Comments

Projects
None yet
4 participants
@cdie
Copy link

cdie commented Nov 3, 2017

When EF auto generates index of multiples column with very long name, it can be longer than 128 chars, which is not allowed by SQL Server

Steps to reproduce

Code :

class Tab
    {
        public int Id { get; set; }
        public string Value1 { get; set; }
        public string Value2 { get; set; }
        public string Value3 { get; set; }
        public string Value4 { get; set; }
        public string Value5 { get; set; }
        public string Value6 { get; set; }
    }

class Ctx : DbContext
    {

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            var e = modelBuilder.Entity<Tab>().ToTable("A_VERY_SUPER_LONG_TABLE_NAME_TO_BEGIN_WITH");
            e.Property(t => t.Value1).HasColumnName("MY_LONG_VALUE_1_COLUMN");
            e.Property(t => t.Value2).HasColumnName("MY_LONG_VALUE_2_COLUMN");
            e.Property(t => t.Value3).HasColumnName("MY_LONG_VALUE_3_COLUMN");
            e.Property(t => t.Value4).HasColumnName("MY_LONG_VALUE_4_COLUMN");
            e.Property(t => t.Value5).HasColumnName("MY_LONG_VALUE_5_COLUMN");
            e.Property(t => t.Value6).HasColumnName("MY_LONG_VALUE_6_COLUMN");

            e.HasIndex(nameof(Tab.Value1), nameof(Tab.Value2), nameof(Tab.Value3), nameof(Tab.Value4), nameof(Tab.Value5), nameof(Tab.Value6));

        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=EF_Tests;Trusted_Connection=True;MultipleActiveResultSets=true");
        }

    }

Call Context.Database.EnsureCreated to see exception

Further technical details

EF Core version: 2.0.0
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: VS 2017 15.4.2

@smitpatel smitpatel added the type-bug label Nov 3, 2017

@ajcvickers

This comment has been minimized.

Copy link
Member

ajcvickers commented Nov 6, 2017

@cdie The workaround here is to name the index explicitly using the HasName API.

@ajcvickers ajcvickers added this to the 2.1.0 milestone Nov 6, 2017

@AndriySvyryd

This comment has been minimized.

Copy link
Member

AndriySvyryd commented Nov 13, 2017

This depends on #9209

AndriySvyryd added a commit that referenced this issue Nov 16, 2017

Allow providers to limit the length of the generated identifiers.
Move identifier uniquification to conventions to make it deterministic.

Fixes #9209
Fixes #10213

AndriySvyryd added a commit that referenced this issue Nov 16, 2017

Allow providers to limit the length of the generated identifiers.
Move identifier uniquification to conventions to make it deterministic.

Fixes #9209
Fixes #10213

AndriySvyryd added a commit that referenced this issue Nov 17, 2017

Allow providers to limit the length of the generated identifiers.
Move identifier uniquification to conventions to make it deterministic.

Fixes #9209
Fixes #10213

AndriySvyryd added a commit that referenced this issue Nov 17, 2017

Allow providers to limit the length of the generated identifiers.
Move identifier uniquification to conventions to make it deterministic.
Fix default decimal type mapping validation in SqlServer.

Fixes #9209
Fixes #10213
Fixes #10329

AndriySvyryd added a commit that referenced this issue Nov 20, 2017

Allow providers to limit the length of the generated identifiers.
Move identifier uniquification to conventions to make it deterministic.
Fix default decimal type mapping validation in SqlServer.

Fixes #9209
Fixes #10213
Fixes #10329

AndriySvyryd added a commit that referenced this issue Nov 20, 2017

Allow providers to limit the length of the generated identifiers.
Move identifier uniquification to conventions to make it deterministic.
Fix default decimal type mapping validation in SqlServer.

Fixes #9209
Fixes #10213
Fixes #10329

@AndriySvyryd AndriySvyryd removed their assignment Nov 21, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment