Entity framework 将比较函数作为参数传递到实体框架

Entity framework 将比较函数作为参数传递到实体框架,entity-framework,lambda,Entity Framework,Lambda,我有两个实体框架函数,它们只在运算符上有所不同,例如 public int GetCountEqual(int i) { return Context.Entity.Where(e => e.Value == i).Count(); } public int GetCountLess(int i) { return Context.Entity.Where(e => e.Value < i).Count(); } public int GetCountLessOrE

我有两个实体框架函数,它们只在运算符上有所不同,例如

public int GetCountEqual(int i)
{
  return Context.Entity.Where(e => e.Value == i).Count();
}

public int GetCountLess(int i)
{
  return Context.Entity.Where(e => e.Value < i).Count();
}

public int GetCountLessOrEqual(int i)
{
  return Context.Entity.Where(e => e.Value <= i).Count();
}
public int GetCountEqual(int i)
{
返回Context.Entity.Where(e=>e.Value==i.Count();
}
公共整数(整数i)
{
返回Context.Entity.Where(e=>e.Valuee.Value
public int GetCount(表达式whereExpression)
{
返回Context.Entity.Where(whereExpression.Count();
}
int countEqual=GetCountEqual(e=>e.Value==i);
int=GetCountEqual(e=>e.Valueint countLessOrEqual=GetCountEqual(e=>e.Value谢谢!这就回答了问题。对不起,现在还不能给你投票。问后续问题的正确格式是什么?编辑它还是问一个新问题?我只能在实体的函数上传递表达式吗?或者更直接地在字符串上传递什么?因为我的“whereExpression”必须处理Entity的两个字符串属性(取决于它们的值),我想在字符串上传递lambda,而不是在Entity上传递表达式。好的。在@aducci上发布后续消息。调用Count()之前,它不会加载所有数据吗?
public int GetCount(Expression<Func<Entity, bool>> whereExpression)
{
   return Context.Entity.Where(whereExpression).Count();
}

int countEqual = GetCountEqual(e => e.Value == i);
int countLess = GetCountEqual(e => e.Value < i);
int countLessOrEqual = GetCountEqual(e => e.Value <= i);