Tuesday, 15 April 2014

What is Query?

A query is a set of instructions that describes 
  • what data to retrieve from a given data source (or sources) 
  • and what shape and organization the returned data should have.
Execution of LINQ involve three operations
  • Obtain Datasource
  • Create Query Expression
  • Execute Expression

I. Obtain Data Source

Earlier: The source data is organized logically as a sequence of elements of the same kind. 
  • A SQL database table contains a sequence of rows.
  • an ADO.NET DataTable contains a sequence of DataRow objects.
  • XML file, there is a "sequence" of XML elements (although these are organized hierarchically in a tree structure). 
  • Collection contains a sequence of objects.
WITh LINQ: the specific type and structure of the original source data is not important.  The application always sees the source data as an IEnumerable<T> or IQueryable<T> collection. 


II. Query Expression

  • Query Expression can be used to query and to transform data from any LINQ enabled data source.
  • A query expression must begin with a from clause and must end with a select or group clause.

II. Execute Expression
  • A query is not executed until you iterate over the query variable in foreach statement.

No comments:

Post a Comment