5
I’m getting the following error while trying to list all the records of a model:
Sqlnullvalueexception: Data is Null. This method or Property cannot be called on Null values. System.Data.Sqlclient.SqlBuffer.get_Int32()
My method:
//GET: api/empresa
[HttpGet]
public async Task<ActionResult<IEnumerable<Empresa>>> getEmpresas()
{
return await _context.Empresas.ToListAsync();
}
My model:
public class Empresa
{
public int Id { get; set; }
public string Nome { get; set; }
public string Cep { get; set; }
public string Logradouro { get; set; }
public string Complemento { get; set; }
public int Numero { get; set; }
public string Bairro { get; set; }
public string Localidade { get; set; }
public string UF { get; set; }
public int Unidade { get; set; }
public int IBGE { get; set; }
public int GIA { get; set; }
public string Telefone{get;set;}
}
In my comic this is the columns and the result of selecting all the records:
So I researched this error happens when you have a non-null column in the bd, but in this case only the Id (primary key) is non-null, but it is already auto-incremented.
the wretched is a genius
– Sérgio S. Filho