【发布时间】:2017-04-01 18:54:38
【问题描述】:
我有一个通用存储库,如下所示:
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,但现在我需要根据用户输入的搜索词搜索实体(表)。是否可以通过以下方式做到这一点:
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。
标签: c# linq generics repository