logo
Учебник_ПОА

Writing linq Queries

Whether you are working with ADO.NET datasets, SQL databases, .NET collections, or XML documents, the basic structure of a LINQ query expression is the same. A query expression is starts with a from clause, followed by query clauses such as where, orderby, select, and so on. The complete expression is stored in a query variable which can be executed or modified any number of times. Query expression syntax resembles the syntax of SQL. For example, you could write a LINQ query that returns all students in a students database that have science as their major, by using the following syntax:

IEnumerable<Student> studentQuery =

from student in studentApp.students

where student.Major == "Science"

select student;