The query operator and the Linq operator of Linq.

Source: Internet
Author: User

The query operator and the Linq operator of Linq.

Linq has expression syntax and method calling syntax. Both can be used in combination. Expression syntax looks clear, and the syntax for calling methods provides more functions. This article describes expression syntax. For method syntax, see the extension methods in namespaces such as System. Linq. Linq can be used only for classes that implement the IEnumerable or IEnumerable <T> interface, that is, all classes that can use foreach can use linq.

Note that there are some differences between the 3.5 and 4.0 versions of the linq keyword. The following is based on 4.0.

1. Projection Operator

Select: projection of values in the set and sequence. From c in contact select c;

2. Restricted Operators

Where: Same as where in SQL statements, it is used to filter data. From c in contact where c. Lastname = "Josn" select c;

3. Sorting Operators

OrderBy: sorts the return values in ascending order. From c in contact orderby c. Lastname select c;

OrderBy Descending: sorts the return values in Descending order. From c in contact orderby c. Lastname descending select c;

3. Join Operators

Join: You can connect multiple data sources. From c in contact join e in employee on c. ID equals e. ContactID select c;

4. grouping operators

Groupby: groups values in the data source based on a specific value. Similar to group by in SQL statements. From c in contact groupby (c => c. Nationality) select c;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.