I have a table in a Firebird database
CREATE TABLE CIDADE (
CID_CD SMALLINT NOT NULL,
CID_DS CHAR(20) NOT NULL,
CID_UF CHAR(2) NOT NULL,
CID_DISTANCIA_SEDE SMALLINT NOT NULL,
CID_CD_ALTERNATIVO INTEGER NOT NULL,
CID_DT_LK DATE NOT NULL);
I am making a query using LINQ in the columns of this table and am getting the error in columns of CHAR type:
arithmetic exception, numeric overflow, or string truncation string right truncation
Identifying the problem, I noticed that the size of the fields of type String are bursting the limit of the fields. What I'm not understanding is that I'm passing exactly the limit amount of fields.
Here is my code:
public IQueryable<Cidade> Pesquisar(Cidade cidade)
{
string uf = cidade.UF; // "SP" por exemplo
var query = pctxContexto.Cidade.Where(c=> c.UF.Contains(uf));
return query;
}
}
Mapping:
//Mapeamento de tabela
ToTable("CIDADE");
//Chave primária
HasKey(t => new { t.Codigo });
//Propriedades
Property(t => t.Codigo).HasColumnName("CID_CD");
Property(t => t.Descricao)
.IsRequired()
.HasMaxLength(20)
.HasColumnType("Varchar")
.HasColumnName("CID_DS");
Property(t => t.UF)
.IsRequired()
.HasMaxLength(2)
.HasColumnType("Char")
.HasColumnName("CID_UF");
Property(t => t.DistanciaSede)
.IsRequired()
.HasColumnType("Smallint")
.HasColumnName("CID_DISTANCIA_SEDE");
Property(t => t.Codigo_Alternativo)
.IsRequired()
.HasColumnType("Int")
.HasColumnName("CID_CD_ALTERNATIVO");
public Cidade()
{
Codigo = null;
Descricao = string.Empty;
UF = string.Empty;
DistanciaSede = 0;
Codigo_Alternativo = 0;
}
[Key]
public int? Codigo { get; set; }
public string Descricao { get; set; }
public string UF { get; set; }
public Int16 DistanciaSede { get; set; }
public Int32 Codigo_Alternativo { get; set; }
Could someone explain to me why this error occurred and what is the most elegant way to solve it?