【发布时间】:2016-08-03 14:25:05
【问题描述】:
这是我的通用存储库类方法:
public IEnumerable<T> GetBy(Expression<Func<T, bool>> condition)
{
return Context.Set<T>().Where(condition).ToList();
}
我想这样称呼它:
resultCandidate = _repo.GetBy(p => members.Select(s=>s.MemberID).Contains(p.CandidateMemberID)).ToList();
但是当我尝试它时,它会抛出一个错误,例如“无法创建StateInfo 类型的常量值。此上下文中仅支持原始类型或枚举类型。”
我应该这样调用方法。我尝试condition.Compile() 并且它工作但没有像我想要的那样工作。因为它在生成 SQL 查询时没有得到 where 子句。
注意:成员是List<MemberInfo>
谢谢
【问题讨论】:
标签: c# entity-framework linq