0
I need to return all records containing the branch informed using the clause where
, only that the Entity Framework is returning all records ignoring what is in the where
. Where am I going wrong?
public IQueryable<PessoaGenerico> GetAllPessoaGenericoByFilial(int id)
{
return DbSet
.Where(pg => pg.PessoaFilialId == id)
.AsQueryable()
.AsNoTracking();
}
In the example, I’m searching all the records where PessoaFilialId
is equal to 31. He should not find and return null
, but it’s bringing all.
Thanks for the @Barbetta return, but it didn’t work with Tolist(). It keeps bringing all the records.... strange this...
– Master JR
@Jalberromano that weird, I don’t see anything different in the code anymore.. Let’s do some rsrs tests, try it like this
public List<SuaClasse> GetAllPessoaGenericoByFilial(int id)
 {
 return DbSet.Where(pg => pg.PessoaFilialId == id).AsNoTracking().ToList();
 }
changing the method directly.DbSet
where you form him?– Barbetta
I think I figured out the problem... I was validating inside an if (with my repository function and the return was not null... The return is coming (Empty = "Enumeration yielded in Results")... Why in some cases the return is null and in other Empty? I’ll take care of Empty?
– Master JR
Pera, let’s separate the cases, there in the print your are returning value, after using the
ToList()
stopped coming value? or even with theIQueryable
is returningEmpty
?– Barbetta
No. It’s just that I was validating like this: "if ( _personGenericoRepository.Getallpersongenericobyfilial(personGenerico.Pessoaid) != null)". When I "debbugava" and positioned the mouse over personally EnericoRepository, all records were returned (with or without Tolist), but it was because the function was within If. Now I’ve validated it like this: "var test = _personGenericoRepository.Getallpersongenericobyfilial(personGenerico.Pessoaid); if (test != null)" and the return is Empty , because Ienumerable and Iquerable returns Empty when not found... I just need to treat when I’m Empty....
– Master JR
In short: I need to treat the return "Empty", that is, if the return is different from Empty....
– Master JR
I edited the answer with the one If(list.Any()),tries it to see if it will work
– Barbetta
It worked 100%!!!! Thanks Bro!!!
– Master JR