3

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 runs, I'm assuming the processing power for the query is coming from the computer running the program.

But when this code runs:

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

Is the processing power running the query coming from the computer running the program, or from the computer with SQL Server installed on it that I've connected to in my connection string?

Charles Clayton
  • 17,005
  • 11
  • 87
  • 120
  • Are you using LINQ-to-SQL? It will transform the lambda expression into a SQL statement. You can see the query with ToString(); see [this](http://stackoverflow.com/a/18237349/772086) link. – Mike Jul 20 '15 at 22:34
  • 1
    In the second case, the 'querying' power comes from the database; there is still a bit of overhead for the application server, though, as it has to create the SQL statement and bind the results to objects (entities). – ps2goat Jul 20 '15 at 22:34

2 Answers2

1

It depends on the query provider. Usually, the point of having a query provider is remoting the query to another machine. The provider is in control of everything. Some parts of the query might run on the client. LINQ to SQL was able to do that. In all cases at least a few cycles will be spent in the provider as overhead or to provide features such as entity tracking.

usr
  • 168,620
  • 35
  • 240
  • 369
1

I'm assuming you are talking about Linq to SQL (there are other adapters), in that 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 running the Sql Server.

Jaime
  • 6,736
  • 1
  • 26
  • 42