我有一個通用的存儲庫,像這樣:如何獲得一個實體的名單與通用搜索
public IEnumerable<T> SelectAll()
{
return table.ToList();
}
public T SelectByID(object id)
{
return table.Find(id);
}
public void Insert(T obj)
{
table.Add(obj);
}
也能正常工作的基本CRUD,但現在我需要尋找對一個實體(表)用戶輸入了searchterm。它是在所有可能的東西像這樣做:
public IEnumerable<T> SelectAll(T obj, string searchText, string columnName)
{
// I am not sure what code to write here... It should give me all the records that contain the search term.
// I was thinking something like this could be made to work...but I need help with it.
return table.GetType().GetProperty(columnName).GetValue())ToList();
}
使用動態Linq。 –