Linq utility instance

Source: Internet
Author: User

The purpose of this article is to share with netizens the practices of Linq in projects. Projects I have participated in can see the shadows of Linq. (LinqTosql, LinqToString, LinqToXML, LinqToEntity, and so on...) I personally think that Linq is a very successful technology launched by Microsoft in recent years. For example, when I am familiar with Linq and use SQL to write business logic, I feel that I am no longer used to it. If you have not studied Linq in the system, I hope this article will help you.

This article will introduce the application scope of Linq in actual development from the following aspects:

1. LinqToXML

Add an xml file to the test project:

You can add, delete, modify, and query XML files by operating xml files with the following code:

2. LinqToEntity

Use EF to operate the NorthWind database:

Note: The generated SQL statements are:

Inner Join:SELECT \ r \ n1 AS [C1], \ r \ n [Extent1]. [CompanyName] AS [CompanyName], \ r \ n [Extent2]. [OrderDate] AS [OrderDate] \ r \ nFROM [dbo]. [MERs] AS [Extent1] \ r \ nINNER JOIN [dbo]. [Orders] AS [Extent2] ON [Extent1]. [CustomerID] = [Extent2]. [CustomerID]

Outer Join:SELECT \ r \ n1 AS [C1], \ r \ n [Extent1]. [CompanyName] AS [CompanyName], \ r \ n [Extent2]. [OrderDate] AS [OrderDate] \ r \ nFROM [dbo]. [MERs] AS [Extent1] \ r \ nLEFT outer join [dbo]. [Orders] AS [Extent2] ON [Extent1]. [CustomerID] = [Extent2]. [CustomerID]

 

3. LinqToFile

To operate disk files using Linq:

4. LinqToArray

Array of Linq operations:

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.