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'm doing a query using LINQ with table columns and I'm getting the error in the CHAR type columns:
arithmetic exception, numeric overflow, or string truncation string right truncation
Identifying the problem, I realized that the size of type String fields are beyond the limits of the field. I do not understand this, because I mapped the correct length constraints on these fields.
Follows my code:
public IQueryable<Cidade> Pesquisar(Cidade cidade)
{
string uf = cidade.UF; // "SP" for example
var query = pctxContexto.Cidade.Where(c=> c.UF.Contains(uf));
return query;
}
Mapping:
// Table Mapping
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("Char")
.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");
How can I solve this problem? Why is it occurring?