In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to solve the Linq sentence problem, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
The Navigation class provides the ability to obtain the specified Url permissions, using basic Linq statements:
Public static int GetPermission (string Url) {var item = Links.Where (p = > p.Url = = Url). ToList (); if (item.Count > 0) {return item [0] .permission;} return 0;}
Because, when generating html, it is considered that if there are no items under a category according to the corresponding permissions, the category will not be displayed. Therefore, the Index is more complicated and grouped according to the corresponding permissions, so the corresponding Linq statement is also more complex, using group by:
Public static int GetIndex (string Url, int Permission)
{
Int id = FindCategoryId (Url)
Var item = from p in Links where (p.Permission & Permission) = =
Permission & & p.Category_Id! = 0
Group p by p.Category_Id into g select new {Category_Id = g.Key}
Var I = item.ToList () .FindIndex (p = > p.Category_Id = = id)
Return I p.Url = = Url) .ToList ()
If (item.Count > 0)
{
Return item [0] .Category _ Id
}
Return 0
}
Although I am using in-memory data, because the format is a very standard database format, it is also very convenient to put this configuration item in a database table or serialize it into XML-although I don't think this is necessary.
From an implementation point of view, the speed of this method should not be very fast, however, because the amount of data is small, and for the page, these in-memory manipulation can only be regarded as a small Case, so there is no obvious difference in speed.
However, at present, there are still some dissatisfaction with this solution. For example, if the Hide parameter is changed to be similar to Permission, you can control the display of each item under different permissions, which is much more flexible than the simple global Hide. For example, there is no judgment on whether there will be two dividing lines and so on.
Another implementation is to put the definition of the data on each page, so that although the settings are scattered to each page, it is more in line with the actual situation. Moreover, the page Url can also be obtained by reflection, and it is easier to delete the page or rename the page, which may be a better solution.
Thank you for reading this article carefully. I hope the article "how to solve the problem of Linq sentences" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you 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.