In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the shortcomings of Linq To Sql". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what are the shortcomings of Linq To Sql.
Shortcomings of Linq To Sql
A long time ago, a netizen asked such a question. He has a DataView on the interface that binds some Column, and then he checks that column and sorts it by a column. The parameter it returns is the name of the column. Then ask me how to use Dlinq to achieve this.
In the old days of concatenating Sql statements, this was very simple, a "order by" + string, and you could arrange whatever you wanted. Now, dlinq is a property of an object, and it is no longer possible to concatenate. The answer I gave him at that time was like this.
Private void Methods (string orderId) {var Q = db.Customers.Select (c = > c); switch (orderId) {case "ID": qq = q.OrderBy (c = > c.ID); break; case "Name": qq = q.OrderBy (c = > c.Name); break; default: break;} var result = q.ToList ();}
I didn't come up with a better plan at that time. Then tell him to check out Compiled Query. Maybe we can find something more convenient. Later, I saw something more convenient in this example.
Var query = db.Customers.Where
("City = = @ 0 and Orders.Count > = @ 1", "London", 10).
OrderBy ("CompanyName").
Select ("New (CompanyName as Name, Phone)")
Here, what OrderBy receives directly is the name of the column. If you take a closer look, it seems that Where is a Linq sentence, but OrderBy should also be a linq statement. Later, I changed the CompanyName to lowercase and ran past it. Is it really the name of the column? Let's have a problem. Found a column name, is with a space, re-build this project. A run, wrong! It is also wrong to expand the list with a Chinese extension. Well, it's just a dynamic construction of Expression Tree, and you can never accept the name of a column directly. This example looks very simple, but I don't know if you have noticed that it has a Dynamic.cs file of more than 80k. What's more interesting is that its namespace is System.Linq.Dynamic. It seems that ms was going to add it to. Net 3.5. I don't know why I put it in the example. Under this namespace, its main content is to dynamically construct Expression Tree. It is similar to the method in the dynamic query article of Linq To Sql advanced series (6) using object. However, it also contains the parsing string part.
From the above example, you can see that Linq To Sql is much more troublesome than concatenating sql in constructing statements dynamically. In the article of dynamic query with object in the Linq To Sql advanced series (6), the author highly recommends the use of object query. This is in line with the design principles of Linq To Sql. Because, it is mainly to solve the problem of data collection objects. All its operations are for object, so let's use object query.
At this point, I believe you have a deeper understanding of "what are the shortcomings of Linq To Sql?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.