Problem in FK name size

Asked

Viewed 119 times

1

I have a WebApi to work with a Firebird 2.5, I used the EF at the time, but today I am presenting the following error

"The name 'FK_ARRUMACAO_CHECKLIST_ARRUMACAO_ARRUMACAO_ID' is longer than Firebird’s 31 characters limit for Object Names."

I know there’s a limit to naming the camps Colunas, Tabelas, Indices, etc in Firebird, and as it is a basis of a legacy system does not have the correct mapping of entities, in the base will hardly possess FK, for some reason the EF is automatically generating the name FK by exceeding the character limit, I wonder if there is any way to set the name of Foreignkey by EF either by Dataannotations or even Fluentapi?

[Table("IMPRESSAO_DETALHE")]
public class ImpressaoDetalhe
{
    [Column("ID")]
    public int Id { get; set; }
    [Index("IX_IMP_DET_IMP_ID")]
    [Column("ID_IMPRESSAO")]
    public int ImpressaoId { get; set; }
    [Column("LINHA")]
    public string Linha { get; set; }
    [Column("ORDEM")]
    public int Ordem { get; set; }

    public virtual Impressao Impressao { get; set; }
}

I can name the index

[Index("IX_IMP_DET_IMP_ID")]

But for FK Dataannotations is not possible

1 answer

2

When you create a property with a Dataannotation ForeignKey referencing your browsing property (in this case it is the property Impressao), Entity Framework creates the name of your ForeignKey equal to your property that owns Dataannotation.

[Table("IMPRESSAO_DETALHE")]
public class ImpressaoDetalhe
{
    [Column("ID")]
    public int Id { get; set; }

    [Index("IX_IMP_DET_IMP_ID")]
    [ForeignKey("Impressao")]
    public int ImpressaoId { get; set; }

    [Column("LINHA")]
    public string Linha { get; set; }

    [Column("ORDEM")]
    public int Ordem { get; set; }

    public virtual Impressao Impressao { get; set; }
}

In this case your Foreignkey in the database will have the name ImpressaoId, because it is the name of your property that is referencing the navigation property Impressao.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.