I'm working on creating a Get
service in ASP.NET Core, my project contains the following structure:
Certiao.Data - Class Library
Inside it has 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();
}
}
}
}
SexController.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 at SexoController
, as in the image below:
Why did you make this mistake in my implementation? I'm just trying to get data from the Sexo
table of SQL Server when trying to run my GET
method.