我正在使用通用函數來過濾記錄列表。使用動態查詢庫的C#篩選器列表?
功能如下:
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。我需要將其作爲通用過濾器,以便我可以傳遞任何集合,然後獲取過濾結果。
試試這個話題http://stackoverflow.com/questions/7557761/apply-多重過濾到wpf-datagrid-using-c-sharp可能你可以得到一些想法。 – Godfre
這個問題是由我問:) – sony