我正在使用一个通用函数来过滤记录列表。
功能如下:
class FilterRecords
{
public static object ParseExpression(string Condition, string FilterColumn)
{
string _operator = "";
string _condition = "";
if (Condition.Substring(0, 1) == "<" || Condition.Substring(0, 1) == ">")
{
_operator = Condition.Substring(0, 1);
if (Condition.Substring(1, 1) == "=")
{
_operator += "=";
_condition = Condition.Substring(2);
}
else
{
_condition = Condition.Substring(1);
}
_operator = "=";
return (dbContext.OrdsRlsds.AsQueryable().Where(FilterColumn + " " + _operator + " " + " @0", _condition).ToList());
}
else
{
if (Condition.Contains(','))
{
string[] conds = Condition.Split(',');
return (dbContext.OrdsRlsds.AsQueryable().Where(FilterColumn + " >= @0 && " + FilterColumn + " <= @1", conds).ToList());
}
else
{
return (dbContext.OrdsRlsds.AsQueryable().Where(FilterColumn + " == @0", Condition).ToList());
}
}
}
}
该函数使用动态查询库。目前,它只过滤一种类型的记录——OrdsRlsds。我需要使它成为一个通用过滤器,以便我可以传递任何集合,然后返回过滤后的结果。