0
I’m starting with Entity following this tutorial.
My method is giving error in function at the time of Savechanges();
My Controller:
[Route("api/[controller]")]
[ApiController]
public class EmpresaController : ControllerBase
{
private readonly CrudContext _context;
public EmpresaController(CrudContext context)
{
_context = context;
if(_context.Empresas.Count() == 0)
{
_context.Empresas.Add(new Empresa { Nome = "Empresa", Cep = "14620-000"});
_context.SaveChanges();
}
}
//GET: api/empresa
[HttpGet]
public async Task<ActionResult<IEnumerable<Empresa>>> getEmpresas()
{
return await _context.Empresas.ToListAsync();
}
My class Company:
{
public class Empresa
{
public long 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 string Unidade { get; set; }
public int IBGE { get; set; }
public int GIA { get; set; }
}
When I hit the api/company I get:
Invalidcastexception: Unable to cast Object of type 'System.Int32' to type 'System.Int64
In the database, what is the type of column?
– Leandro Angelo
And on which property you are finding the error?
– Leandro Angelo