1
I am acting in the creation of a service Get
in ASP.NET Core, my project contains the following structure:
Certidao.Data - Class Library
Inside there is Dependences
, Models
: Sexo.cs
and DB_SDO_DEVContext.cs
Db_sdo_devcontext.Cs
public DB_SDO_DEVContext(DbContextOptions<DB_SDO_DEVContext> options)
: base(options)
{
}
Sex.Cs
public partial class Sexo
{
public Sexo()
{
Pesvtmocrctdatd = new HashSet<Pesvtmocrctdatd>();
}
public short Id { get; set; }
public string Descricao { get; set; }
public string Abreviacao { get; set; }
public ICollection<Pesvtmocrctdatd> Pesvtmocrctdatd { get; set; }
}
Repositories> Interfaces: Isexorepository.Cs
{
public interface ISexoRepository
{
IEnumerable<Sexo> ConsultaSexoIds(List<int> ids);
}
}
Sexorepository.Cs
public class SexoRepository : RepositoryBase<Sexo>, ISexoRepository
{
public IEnumerable<Sexo> ConsultaSexoIds(IEnumerable<int> ids)
{
using (var Db = new DB_SDO_DEVContext())
{
return (from sexo in Db.Sexo
where ids.Contains(sexo.Id)
select sexo).ToList();
}
}
}
}
Sexocontroller.Cs
{
[Route("api/[controller]")]
[ApiController]
public class SexoController : ControllerBase
{
private readonly DB_SDO_DEVContext contexto;
[HttpGet]
public ActionResult<List<Sexo>> GetAll()
{
return contexto.Sexo.ToList();
}
}
}
An error occurs when it arrives in SexoController
, as in the image below:
Why did you give this error in my implementation? I’m just trying to bring data from the table Sexo
SQL Server when trying to run my method GET
.