我想为了报告的目的过滤我的列表,但我想让它尽可能地动态,以便用户可以过滤1个或多个列。
我的想法是创建一个Dictionary,然后将其传递给一个方法,该方法将过滤出相关的记录,但我现在被困在如何做“动态”部分。
到目前为止,我的当前代码看起来就是这样,但它不起作用。
filters = {CourseId,2},{CourseDescription,Maths}
public IQueryable<Course> Filter(Dictionary<string,string> filters)
{
var a = from s in context.Courses
select s;
foreach (var filter in filters)
{
if(!string.IsNullOrEmpty(filter.Value))
{
a = a.Where(s => s./*filter.Key*/.ToUpper().Contains(/*filter.value*/.ToUpper()));
}
}
}请有人可以帮助我,并指出正确的方向,以便我可以让这项工作。
谢谢。
发布于 2014-01-17 07:59:45
我最近刚刚使用http://www.albahari.com/nutshell/predicatebuilder.aspx根据收到的标准动态构建了一个用于实体框架的谓词。工作得很好。
https://stackoverflow.com/questions/21175355
复制相似问题