表达式树,传递 group
public class Test<T> where T : class
{
MoviesEntities db = new MoviesEntities();
public virtual List<IGrouping<S,T>> FindList<S>(Expression<Func<T, S>> groupBy)
{
var _list = db.Set<T>().AsNoTracking().GroupBy<T, S>(groupBy);
return _list.ToList();
}
}
调用
Test<Movies> t = new Test<Movies>();
var q = t.FindList(x => new { x.ID, x.ImageType });
结果: