![](/img/trans.png)
[英]I'm trying to grasp the concept of creating a program that uses a SQL Server database, but I'm used to running it only on my local machine
[英]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 Server的计算机,我连接到我的连接字符串?
这取决于查询提供程序。 通常,拥有查询提供程序的重点是将查询远程连接到另一台计算机。 提供者控制着一切。 查询的某些部分可能在客户端上运行。 LINQ to SQL能够做到这一点。 在所有情况下,至少几个周期将作为开销用于提供者或提供诸如实体跟踪之类的功能。
我假设您正在谈论Linq to SQL(还有其他适配器),在这种情况下,Linq to Sql驱动程序将Linq查询转换为常规的Sql查询。
所以要回答这个问题,大部分工作都是由运行Sql Server的计算机完成的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.