LINQ is a new thing, but from many articles and discussions, this concept is a bit chaotic. Therefore, we often see the following:
- Only data tables and object attributes can be matched one by one in LINQ ......
- LINQ Development Guide: map database fields in LINQ ......
In fact, the above two statements refer to the use of LINQ to SQL instead of the use of LINQ. It may be because of the widest image rate of LINQ to SQL (even the first example of About LINQ on MSDN is to query the database), so many people use the combination of LINQ to SQL and LINQ, this will cause misunderstanding for beginners. I think that LINQ is a LINQ to SQL, and LINQ to SQL is a LINQ-this is certainly not the case.
LINQIs short for Language-Integrated Query. It is a new Language feature in C #3.0 and VB 9.0. It can be used for set-based operations in programming. This can greatly simplify the development process and improve development efficiency. For example:
List<User> userList = GetUserList();var userWithOddId = from u in userList where u.UserID % 2 == 1 select u; foreach (User u in userWithOddId){ Console.WriteLine(u.UserName);}
If you want to filter out User objects with an odd number of IDs without LINQ, you need to create a List, traverse the entire List, and add the User objects that meet the specified conditions to the new List. With LINQ, this part of filtering becomes very easy, and can be completed in just one sentence. If you think this example is not enough to show that LINQ has made a significant contribution to productivity, please follow my next article (for now, "Why should we embrace LINQ"). In the above Code, the return value is IQueryable <T> or IEnumerable <T>.
LINQ to SQLIs a lightweight O/R Mapping solution built in. NET 3.5. It can map data tables to object objects to facilitate developers' operations on databases. It can be seen that LINQ to SQL is only an implementation of LINQ and provides a LINQ Provider that can query the SQL Server database.
LINQ ProviderIs the executor of the LINQ query. The standard LINQ syntax supports many operators, but a specific LINQ implementation may only support some of them. By default, in. NET 3.5, three types of LINQ providers are provided, namely, LINQ to Object (the above example), LINQ to SQL, and LINQ to XML.
LINQ to XXX indicates a solution to query data such as XXX using LINQ. We can customize the LINQ Provider and use our custom query rules to process specific datasets. Currently, dozens of LINQ providers (such as LINQ to Flickr, and LINQ to NHibernate) can be found on the Internet, and ADO is already in beta 3. NET Entity Framework, and finally provides a LINQ Provider called "LINQ to Entities ".