我有一个仓库类,它包装了我的LINQ to SQL数据上下文。该仓库类是一个业务层类,包含所有的数据层逻辑(以及缓存等)。
这是我的Repo接口的第一版。
public interface ILocationRepository
{
IList<Location> FindAll();
IList<Location> FindForState(State state);
IList<Location> FindForPostCode(string postCode);
}
为了处理FindAll的分页,我正在考虑是否应该公开IQueryable<ILocation>而不是IList,以简化像分页这样的情况下的接口。
公开数据存储库中的IQueryable有哪些优缺点?
非常感谢任何帮助。
IEnumerable<T>
,因为如果你没有注意并对同一个列表进行了多次 foreach 循环,它可能会影响性能,这种情况下你将多次调用GetEnumerator()
。 - Wahid Bitar