Error Method Update EF Core with Firebird 2.5

Asked

Viewed 147 times

0

When trying to update an entity Firebird is returning me this error "Implementation limit exceeded block size Exceeds implementation Restriction", simply take the entity of the bank and have it update without changing anything in it, so I saw the link Faqfirebird this error occurs when select exceeds the size of 64kb, but I want to insert an image in the database that is a Blob field.

Class Defining the table

public class Hospede : EntityBase
{
    public string Nome { get; set; }
    public string Email { get; set; }
    public string Sexo { get; set; }
    public string Telefone { get; set; }
    public string TelefoneResidencial { get; set; }
    public string TelefoneCelular { get; set; }
    public DateTime? DataNascimento { get; set; }
    public string RG { get; set; }
    public string CPF { get; set; }
    public string Passaporte { get; set; }
    public string Nacionalidade { get; set; }
    public byte[] AssinaturaDigital { get; set; }
    #region Endereço
    public string Endereco { get; set; }
    public int Numero { get; set; }
    public string Complemento { get; set; }
    public string Bairro { get; set; }
    public string Cidade { get; set; }
    public string Estado { get; set; }
    public string Pais { get; set; }
    public string Cep { get; set; }
    #endregion

    public virtual ICollection<Reserva> Reserva { get; set; }
}

o Mapping of the Entity

public class HospedeMap : IEntityTypeConfiguration<Hospede>
{
    public void Configure(EntityTypeBuilder<Hospede> map)
    {
        map.ToTable("TABHOSPE");
        map.HasKey(x => x.Id);
        map.Property(x => x.Id)
            .HasColumnName("F_COD");
        map.Property(x => x.Nome)
            .HasColumnName("F_NOME");
        map.Property(x => x.Email)
            .HasColumnName("EMAIL");
        map.Property(x => x.Sexo)
            .HasColumnName("F_SEXO");
        map.Property(x => x.Telefone)
            .HasColumnName("F_FONE");
        map.Property(x => x.TelefoneResidencial)
            .HasColumnName("FONERES");
        map.Property(x => x.TelefoneCelular)
            .HasColumnName("FONECEL");
        map.Property(x => x.DataNascimento)
            .HasColumnName("F_NASCIM");
        map.Property(x => x.RG)
            .HasColumnName("F_RG");
        map.Property(x => x.CPF)
            .HasColumnName("F_CPF");
        map.Property(x => x.Passaporte)
            .HasColumnName("PASSAPORT");
        map.Property(x => x.Nacionalidade)
            .HasColumnName("NACIONALIDADE");
        map.Property(x => x.DataNascimento)
            .HasColumnName("F_NASCIM");
        map.Property(x => x.AssinaturaDigital)
            .HasColumnName("ASSINATURA_DIGITAL");
        map.Property(x => x.Endereco)
            .HasColumnName("F_ENDERECO");
        map.Property(x => x.Numero)
            .HasColumnName("NUMERO");
        map.Property(x => x.Complemento)
            .HasColumnName("COMPLEMENTO");
        map.Property(x => x.Bairro)
            .HasColumnName("F_BAIRRO");
        map.Property(x => x.Cidade)
            .HasColumnName("F_CIDADE");
        map.Property(x => x.Estado)
            .HasColumnName("F_ESTADO");
        map.Property(x => x.Pais)
            .HasColumnName("PAIS");
        map.Property(x => x.Cep)
            .HasColumnName("F_CEP");
        map.HasMany(x => x.Reserva)
            .WithOne(x => x.Hospede);
    }
}

Table structure

create table TABHOSPE{
   F_COD integer,
   F_NOME varchar(100),
   F_FONE varchar(20),
   F_SEXO varchar(1),
   F_NASCIM date,
   F_ENDERECO varchar(60),
   F_BAIRRO varchar(60),
   F_CIDADE varchar(60),
   F_ESTADO varchar(2),
   F_CEP varchar(9),
   F_RG varchar(15),
   F_CPF varchar(15),
   NACIONALIDADE varchar(60),
   PAIS varchar(60),
   FONERES varchar(20),
   FONECEL varchar(20),
   EMAIL varchar(80),
   PASSAPORT varchar(20),
   COMPLEMENTO varchar(30),
   NUMERO integer,
   ASSINATURA_DIGITAL Blob
}

1 answer

1

Cannot save to blobs fields very large values at once. As you yourself noted, the maximum size of the SQL statements in Firebird is 64 Kb.

What you should do to circumvent this limit is to break the blob into several smaller parts and first run an INSERT to insert the first part, followed by UPDATE’s that concatenate the other parts. You must do everything in a single transaction and in the end give a COMMIT to effect the change or ROLLBACK to undo.

To concatenate blob fields you must use a function that performs this procedure without losses or corruption, because Firebird does not have this feature natively. I recommend using the library Freeadhoc, it has many functions for complete handling of blob fields.

Official website of Freeadhoc: http://freeadhocudf.org/index_eng.html

Functions page for handling blob fields: http://freeadhocudf.org/documentation_english/dok_eng_blob.html

The library must be installed in your database so that it can be used directly in the SQL statements.

  • I have done several tests in the entity, to try to find the best way to fix, as it is a legacy system the table itself has enough fields, I have reduced the minimum required fields until the error does not happen and I am able to record, if it is necessary to update more fields I will consider using this option or even splitting in two entities to do the CRUD in the bank.

  • Even if your update or Insert instruction has only one blob field, you will always have to take care that the instruction size does not exceed 64 Kb, and what makes things even more complicated is that you need to record an image, so it’s safer to take the image size, divide by 55 and round it up.

Browser other questions tagged

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