ralmsdeveloper / EntityFrameworkCore.FirebirdSQL

FirebirdSQL database provider for Entity Framework Core.
Other
44 stars 26 forks source link

Error creating FK in column with very long name #26

Closed alexandredsimoes closed 6 years ago

alexandredsimoes commented 6 years ago

I have a class with the actual structure:

public class Configuracao{
        ... code ommited for brevity
        public TipoDocumento TipoDocumentoContratoLocacao { get; set; }
        public int TipoDocumentoContratoLocacaoId { get; set; }
        public TipoDocumento TipoDocumentoContratoVenda { get; set; }
        public int TipoDocumentoContratoVendaId { get; set; }
        public TipoDocumento TipoDocumentoComissaoLocacao { get; set; }
        public int TipoDocumentoComissaoLocacaoId { get; set; }
        public TipoDocumento TipoDocumentoComissaoVenda { get; set; }
        public int TipoDocumentoComissaoVendaId { get; set; }
        public TipoDocumento TipoDocumentoRepasseLocacao { get; set; }
}

When i call dbContext.Database.EnsuredCreated(), the following sql script is generated:

CREATE TABLE "Configuracao" (   

    "TipoDocumentoComissaoLocacaoId" INTEGER NOT NULL ,
    "TipoDocumentoComissaoVendaId" INTEGER NOT NULL ,
    "TipoDocumentoContratoLocacaoId" INTEGER NOT NULL ,
    "TipoDocumentoContratoVendaId" INTEGER NOT NULL ,
    "TipoDocumentoRepasseLocacaoId" INTEGER NOT NULL ,
    "UsuarioSugestaoJornalId" INTEGER,
    CONSTRAINT "PK_Configuracao" PRIMARY KEY ("Id"),
    CONSTRAINT "FK_Configuracao_Operadora_Opera" FOREIGN KEY ("OperadoraPadraoId") REFERENCES "Operadora" ("Id") ON DELETE NO ACTION,
    CONSTRAINT "FK_Configuracao_TipoDocumento_T" FOREIGN KEY ("TipoDocumentoComissaoLocacaoId") REFERENCES "TipoDocumento" ("Id") ON DELETE NO ACTION,
    CONSTRAINT "FK_Configuracao_TipoDocumento_T" FOREIGN KEY ("TipoDocumentoComissaoVendaId") REFERENCES "TipoDocumento" ("Id") ON DELETE NO ACTION,
    CONSTRAINT "FK_Configuracao_TipoDocumento_T" FOREIGN KEY ("TipoDocumentoContratoLocacaoId") REFERENCES "TipoDocumento" ("Id") ON DELETE CASCADE,
    CONSTRAINT "FK_Configuracao_TipoDocumento_T" FOREIGN KEY ("TipoDocumentoContratoVendaId") REFERENCES "TipoDocumento" ("Id") ON DELETE NO ACTION,
    CONSTRAINT "FK_Configuracao_TipoDocumento_T" FOREIGN KEY ("TipoDocumentoRepasseLocacaoId") REFERENCES "TipoDocumento" ("Id") ON DELETE NO ACTION,
    CONSTRAINT "FK_Configuracao_Usuario_Usuario" FOREIGN KEY ("UsuarioSugestaoJornalId") REFERENCES "Usuario" ("Id") ON DELETE NO ACTION
);

The Constrainst name "FK_Configuracao_TipoDocumento_T" is repeated for each generated column, throwing a exception.

Firebird version: 3.0 EntityFrameworkCore.FirebirdSql version: 2.0.11.6

ralmsdeveloper commented 6 years ago

@alexandredsimoes Thanks for reporting this, I'll be resolving this as soon as possible. I'll tell you about the progress!

alexandredsimoes commented 6 years ago

I solved the problemn with custom FK names:

modelBuilder.Entity<Configuracao>()
                .HasOne(p => p.TipoDocumentoComissaoLocacao)
                .WithOne()
                .HasForeignKey<Configuracao>(c=>c.TipoDocumentoComissaoLocacaoId)
                .HasConstraintName("FK_Comiss_Loc");
ralmsdeveloper commented 6 years ago

@alexandredsimoes Did you get my email, where did I tell you about this limitation, the size of the names for Firebird?

alexandredsimoes commented 6 years ago

Yeah. Thank you for the support.