LINQ is a new thing, but from many articles and discussions, the concept is a bit confusing. So we can often see this:
- LINQ can only match data tables to entity attribute one by one ...
- LINQ Development Guide: Database field mapping in LINQ ...
In fact, the above two sentences are all LINQ to SQL rather than LINQ. Probably because LINQ to SQL is the most photogenic (even the first example of about LINQ on MSDN is querying the database), so many people are mixing LINQ to SQL with LINQ, which can be misleading to beginners, that LINQ is LINQ to Sql,linq to The fact that SQL is linq--is certainly not the case.
LINQ is the abbreviation for language-integrated query, a newly added language feature in C # 3.0 and VB 9.0 that enables collection-based operations using the built-in query language during programming. This can greatly simplify the development process and improve the development efficiency. For example:
?
1 2 3 4 5 6 7 8 9 |
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 do not have LINQ, to filter out a user object with an odd ID, you need to create a list and then traverse the entire list to put a user object that meets certain criteria into a new list. With LINQ, this part of the filter becomes very easy, even if you need a word to do it. If this example is not enough to show that LINQ contributes significantly to productivity, follow my next article (tentatively titled Why We Embrace LINQ). LINQ specifically refers to the use of From...where...select in the above code, whose return value is iqueryable<t> or ienumerable<t>.
LINQ to SQL is a lightweight O/R mapping solution built into. NET 3.5 that maps data tables to entity objects, allowing developers to manipulate the database. As you can see, LINQ to SQL is only an implementation of LINQ and provides a LINQ Provider that queries the SQL Server database.
LINQ Provider is the executor of a LINQ query, and the standard LINQ syntax supports many operators, but a specific LINQ implementation might support only a subset of them. The. NET 3.5 Default provides three LINQ Provider, namely LINQ to Object (the above example), LINQ to SQL, and LINQ to XML.
LINQ to XXX represents a solution that uses LINQ to query for data such as XXX. We can customize the LINQ Provider to work with specific datasets using our custom query rules. Dozens of types of LINQ Provider, such as LINQ to Flickr,linq to NHibernate, are now available on the Internet and are already in the Beta 3 phase of the ADO Framework, and will eventually provide a LINQ Provider, called "LINQ to Entities".