gpt4 book ai didi

c# - 返回 IQueryable 或不返回 IQueryable

转载 作者:IT王子 更新时间:2023-10-29 03:41:02 26 4
gpt4 key购买 nike

<分区>

我有一个存储库类,它包装了我的 LINQ to SQL 数据上下文。存储库类是包含所有数据层逻辑(以及缓存等)的业务线类。

这是我的 repo 接口(interface)的 v1。

public interface ILocationRepository
{
IList<Location> FindAll();
IList<Location> FindForState(State state);
IList<Location> FindForPostCode(string postCode);
}

但是为了处理 FindAll 的分页,我正在讨论是否公开 IQueryable 而不是 IList 以简化分页等情况的接口(interface)。

从数据存储库中公开 IQueryable 的优缺点是什么?

非常感谢任何帮助。

26 4 0