LINQ 查询使用机器的处理能力 运行 程序还是托管数据库的服务器?

Do LINQ queries use the processing power of the machine running the program or the server hosting the database?

如果我有以下代码

MyDataContext _dataContext = new MyDataContext(MyConnectionString);

List<Airplane> entireTable = _dataContext.AirPlanes
List<Airplane> propellerPlanes = new List<Airplane>();

foreach(AirPlane p in entireTable){
    if(p.IsPropellerPlane) propellerPlanes.Add(p);
}

当此代码运行时,我假设查询的处理能力来自计算机 运行 程序。

但是当这段代码运行时:

List<Airplane> propellerPlanes = _dataContext.Airplanes.Where(a => a.IsPropellerPlane).ToList();

处理能力 运行 查询来自计算机 运行 程序,还是来自安装了 SQL 服务器的计算机,我已经连接到我的连接字符串?

这取决于查询提供者。通常,拥有查询提供程序的目的是将查询远程处理到另一台机器。供应商控制着一切。查询的某些部分可能 运行 在客户端上。 LINQ to SQL 能够做到这一点。在所有情况下,提供商至少会花费几个周期作为开销或提供实体跟踪等功能。

我假设您正在谈论 Linq to SQL(还有其他适配器),在这种情况下,Linq to Sql 驱动程序将 Linq 查询转换为常规 Sql查询大部分。

所以要回答这个问题,大部分工作将由计算机 运行 Sql 服务器完成。