Problem in the size of the FK name

1

I have a WebApi to work with a database of Firebird 2.5 , I used at the time the EF, but today it is presenting me with 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 is a limitation in naming fields Colunas , Tabelas , Indices , etc in firebird, and because it is a base of a legacy system it does not have the correct mappings of the entities, in base it will hardly have FK , for some reason EF is automatically generating the FK name by popping the character limit, I wonder if there is any way to set the ForeignKey name 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 give a name to the index

[Index("IX_IMP_DET_IMP_ID")]

However for FK the DataAnnotations is not possible

    
asked by anonymous 21.09.2018 / 20:33

1 answer

2

When you create a property with a Data_Annotation ForeignKey referencing its navigation property (in this case it is the Impressao) property, the Entity Framework creates the name of its ForeignKey equal to its property that owns the 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 be named ImpressaoId because it is the name of your property that is referencing the Impressao navigation property.

    
07.11.2018 / 12:50