LINQ queries are using the processing power of the machine that is running the program or the server that hosts the database?

If I have the following code

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);
}

      

When this code works, I am assuming that the processing power for the request comes from the computer that the program is running on.

But when this code works:

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

      

Is the processing power running a query coming from the computer running the program, or from the computer running SQL Server that I was connecting to in my connection string?

+3


source to share


2 answers


I'm assuming you are talking about Linq to SQL (there are other adapters), in which case the Linq to Sql driver translates the Linq query into a regular Sql query for the most part.



So, to answer the question, most of the work will be done by the computer that is running the Sql server.

+1


source


It depends on the provider of the request. Typically, the point of presence of the request provider deletes the request to another computer. The supplier controls everything. Some parts of the request can be executed on the client. LINQ to SQL was able to do this. In all cases, at least a few cycles will be spent on the provider as overhead or to provide functionality such as object tracking.



+1


source







All Articles