日期:2014-05-20  浏览次数:20697 次

请问2个接口实现的问题
我看到一篇文章中对EF的IRepository类 增加了2个接口

如下

IQueryable<T> Query(Expression<Func<T, bool>> filter);


IList<T> QueryByPage<TKey>(Expression<Func<T, bool>> filter, Expression<Func<T, TKey>> orderby, int OrderType, int PageSize, int PageIndex, out int recordsCount);


但是没有给出实现的方法,我也不知道怎么在RepositoryBase中实现,也许问题很简单,不过还是需要各位指点下

------解决方案--------------------
IQueryable<T> Query(Expression<Func<T, bool>> filter)
{
return data.Where(x => filter(x));
}
IList<T> QueryByPage<TKey>(Expression<Func<T, bool>> filter, Expression<Func<T, TKey>> orderby, int OrderType, int PageSize, int PageIndex, out int recordsCount)
{
var query = data.Where(x => filter(x)).OrderBy(x => orderby(x));
recordsCount = query.Count();
return query.Skip(pageIndex * pageSize).Take(pageSize).ToList();
}