[英]Return the Sum() of a query, using LinQ and Lambda Expression
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 而这个搜索我实体的所有Disable记录
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? 如何使用Lambda和LinQ使用这些方法返回这些记录?
Use Count instead of Sum 使用计数而不是总和
public CodigosDeOperacao GetTheAmmountOfDisable()
{
//somthing like taht
return Search(c=>c.Ativo).Count();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.