In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to understand LINQ grammar". In daily operation, I believe many people have doubts about how to understand LINQ grammar. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to understand LINQ grammar". Next, please follow the editor to study!
With the evolution of time, the program language repeatedly precipitates experience and abstraction, and then uses concise and intuitive grammar to solve all kinds of problems with common characteristics. Visual Studio 2008 (program code name Orcas), C # 3.0 and VB.NET 9.0 will support the new syntax Language Integrated Query (LINQ) to solve multiple data access as a whole. It is dominated by Anders Hejlsberg. Anders has created popular products such as Turbo Pascal, Delphi, Visual Junction +, and C#, and LINQ is something to be reckoned with by the eye of the killer app creator.
LINQ is a series of language extension modules that support data queries in a type-safe manner. Expect to isolate a variety of data features, whether it's the SQL dialect of each manufacturer's database, or the DOM, XQuery, or XPath of XML, or the property access of a collection of objects. Complete data operations in a common way, such as: selection, comparison, sorting, summary. Wait. Look forward to reducing the burden of program developers learning to manipulate all kinds of data.
LINQ translates the embedded LINQ syntax into the original C # or VB.NET program code through language compilers, and calls the relevant underlying modules to maintain the data in entities. * compiled into IL compatible with .NET Framework 2.0 CLR, so CLR itself does not add modules related to LINQ, but .NET Framework, Visual Studio integrated development environment and program language need to add related functions and syntax.
In my own opinion, LINQ has the following advantages:
◆ simplifies a large number of detailed operations, replacing how (how) to what data: this implicit access optimization is left to experts to do, such as DB engine optimization to access data.
◆ accesses all kinds of data consistently through IEnumerable, and integrates with each other in query syntax: for example, File System, operating system process, Registry, object collection, XML, DB..., all use objects, and everyone's attributes are data. In other words, the data is objectified, the object is digitized, and the syntax and meaning of access are the same.
◆ parallel operations: to deal with large amounts of data, it is not easy for programmers to write for loops and include parallel operations. However, when LINQ is translated into C # or VB.NET program code, a large amount of data can be processed in parallel.
◆ can write data object access process, IntelliSense and strong type checking: compared with the previous ADO.NET plus SQL syntax, LINQ is more intuitive and easier to understand than typed dataset, and more widely used.
When the author talks to many friends about LINQ, the most common question is "is there no need to learn SQL in the future?" Personally, I think it's impossible in a short time. LINQ may reduce programmers' dependence on SQL, but LINQ will not replace SQL. Each of them has its own day. LINQ is the data object language spoken by programmers, SQL is the language spoken by database administrators to the database engine, and LINQ is from the point of view of the application processing data, but SQL is about every detail of the whole database server living effectively and safely.
The immediate question is usually: "is it efficient to wrap data in objects and access data indirectly through entity classes?" "the author cannot answer this, but it has yet to be proved by the real world.
LINQ example
You can directly embed the following syntax in C#: get the Country value of each Customer in the Customer object collection as USA, sort by the City attribute from highest to lowest, and return a collection of new objects created with the string values of the CompanyName and City attributes:
Var matchCustomers = from c in db.Customers where c.Country = = "USA" orderby c.City descending select new {c.CompanyName, c.City}
This LINQ syntax is parsed by the C # compiler and returns the object that implements the IEnumerable interface to the matchCustomers variable. In the query syntax, where, orderby, select and other extension methods (Extension Methods) are called. And define the delegate (delegate) of the anonymous method (Anonymous Methods); require the where method to compare the Country property value of the Customer object in the Customers collection to USA. In other words, c.Country = = "USA" is automatically converted to a delegate in the form of bool Pred (T item). * returns a collection of anonymous type (Anonymous Type) objects with object initialization expressions through the select extension method.
If you don't use LINQ, the above syntax can also be written as follows:
Var matchCustomers = db.Customers.Where (c = > c.Country = = "USA").
OrderByDescending (c = > c.City) .Select (c = > new {c.CompanyName, c.City})
At this point, the study of "how to understand LINQ grammar" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.