我要找的SEARCHTEXT任何列的查询/一般的过滤器字段映射LINQ的IQueryable的一般的过滤器
public static IQueryable<T> Filter<T>(this IQueryable<T> source, string searchTerm)
{
var propNames = typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public).Where(e=>e.PropertyType == typeof(String)).Select(x => x.Name).ToArray();
//I am getting the property names but How can I create Expression for
source.Where(Expression)
}
在这里,我给你一个示例场景现在
从我的HTML5表在Asp.net MVC4中,我提供了一个搜索框来过滤输入文本的结果,它可以匹配任何下面的列/ Menu类属性值,我想在服务器端进行搜索,我该如何实现它。
EF模型类
public partial class Menu
{
public int Id { get; set; }
public string MenuText { get; set; }
public string ActionName { get; set; }
public string ControllerName { get; set; }
public string Icon { get; set; }
public string ToolTip { get; set; }
public int RoleId { get; set; }
public virtual Role Role { get; set; }
}
orPredicate is not initilized它是仅用于谓词还是不同于var orPredicate = properties.Aggregate(predicate,(当前,财产)=> current.Or(CreateLike(property,search))); –
对不起,打字错误,我会改变 –
非常感谢,真的很有帮助如何在使用表达式时忽略大小写区分 –