Permalink
Fetching contributors…
Cannot retrieve contributors at this time
45 lines (39 sloc) 3.95 KB
title ms.custom ms.date ms.prod ms.reviewer ms.suite ms.technology ms.tgt_pltfrm ms.topic ms.assetid caps.latest.revision author ms.author manager
LINQ to SQL Queries
03/30/2017
.net-framework
dotnet-ado
article
f4897aaa-7f44-4c20-a471-b948c2971aae
4
JennieHubbard
jhubbard
jhubbard

LINQ to SQL Queries

You define [!INCLUDEvbtecdlinq] queries by using the same syntax as you would in [!INCLUDEvbteclinq]. The only difference is that the objects referenced in your queries are mapped to elements in a database. For more information, see Introduction to LINQ Queries (C#).

[!INCLUDEvbtecdlinq] translates the queries you write into equivalent SQL queries and sends them to the server for processing. More specifically, your application uses the [!INCLUDEvbtecdlinq] API to request query execution. The [!INCLUDEvbtecdlinq] provider then transforms the query into SQL text and delegates execution to the ADO provider. The ADO provider returns query results as a DataReader. The [!INCLUDEvbtecdlinq] provider translates the ADO results to an xref:System.Linq.IQueryable collection of user objects.

[!NOTE] Most methods and operators on [!INCLUDEdnprdnshort] built-in types have direct translations to SQL. Those that [!INCLUDEvbteclinq] cannot translate generate run-time exceptions. For more information, see SQL-CLR Type Mapping.

The following table shows the similarities and differences between [!INCLUDEvbteclinq] and [!INCLUDEvbtecdlinq] query items.

Item LINQ Query [!INCLUDEvbtecdlinq] Query
Return type of the local variable that holds the query (for queries that return sequences) Generic IEnumerable Generic IQueryable
Specifying the data source Uses the From ([!INCLUDEvbprvb]) or from (C#) clause Same
Filtering Uses the Where/where clause Same
Grouping Uses the Group…By/groupby clause Same
Selecting (Projecting) Uses the Select/select clause Same
Deferred versus immediate execution See Introduction to LINQ Queries (C#) Same
Implementing joins Uses the Join/join clause Can use the Join/join clause, but more effectively uses the xref:System.Data.Linq.Mapping.AssociationAttribute attribute. For more information, see Querying Across Relationships.
Remote versus local execution For more information, see Remote vs. Local Execution.
Streaming versus cached querying Not applicable in a local memory scenario

See Also

Introduction to LINQ Queries (C#)
Basic LINQ Query Operations
Type Relationships in LINQ Query Operations
Query Concepts