The method Contains
usually returns a boolean value (true or false) and not an enumeration.
You can use Where
to create a filter over the Relacoes
, and then use a condition for this filter, so that only the elements matching the condition are returned:
public IEnumerable<Relacao> Listar(int Codigo)
{
// assumindo que uma "relação" possua a propriedade `Codigo`
return this.Context.Relacoes
.Where(rel => rel.Codigo == Codigo)
.ToList();
}
The ToList
at the end serves to obtain the database data at the time it is called. If you do not, the data will only be obtained in the future when the resulting enumeration is used. Without the ToList
we would have a kind of lazy assessment.
If your goal is to have a lazy assessment, then you should remove the call from ToList
, but in this case, I recommend changing the type of return also to IQueryable<Relacao>
:
public IQueryable<Relacao> Listar(int Codigo)
{
// assumindo que uma "relação" possua a propriedade `Codigo`
return this.Context.Relacoes
.Where(rel => rel.Codigo == Codigo);
}