I have this generic method in my repository for searching
public virtual IEnumerable<TEntity> Search(Expression<Func<TEntity, bool>> predicate)
{
return Dbset.Where(predicate);
}
And this one that searches all the Disable records of my entity
public IEnumerable<CodigosDeOperacao> GetDisabled()
{
return Search(c => !c.Active && c.disabled).OrderBy(c=>c.Code);
}
I would like to return the number of disabled, because I will need to know if it equals zero.
So I created this method.
public CodigosDeOperacao GetTheAmmountOfDisable()
{
//somthing like taht
return Search(c=>c.Ativo).Sum();
}
How could I return these records using these methods using Lambda and LinQ?
Use Count instead of Sum
public CodigosDeOperacao GetTheAmmountOfDisable()
{
//somthing like taht
return Search(c=>c.Ativo).Count();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.