In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article shows you how to manage user rights in sqlserver. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can gain something through the detailed introduction of this article.
Menu, there is a relationship between these three tables as follows: User_Role= > RoleId= > RoleMenu RoleMenu= > MenuId= > Menu the business relationship between them is: when the user logs in, get the User_Role list through UserId, and find all the corresponding Menu through User_Role. Now there is a problem, that is, how many roles a user can have, one role has multiple menus, and of course, two different roles can have considerable menu items. There is a problem. The user has a "File" menu in the role of "Administrator", and it also has a "File" menu in the role of "News Administrator", so there will be two completed "File" menus. Next, I use anonymous classes and distinct methods to solve this problem. The code is as follows: the copy code is as follows: class Program {static void Main (string [] args) {# region entity list initialization List userRole = new List {new User_Role ("01", 1), new User_Role ("01", 2), new User_Role ("02", 1),} List roleMenu = new List {new Role_Menu (2pr 3), new Role_Menu (1jue 1), new Role_Menu (1d2), new Role_Menu (2jue 1), new Role_Menu (2jue 2),}; List menu = new List {new Menu (1, "edit", 2), new Menu (2, "file", 1), new Menu (3, "view", 3), new Menu (4, "system", 4),} # endregion var linq = from data1 in userRole join data2 in roleMenu on data1.RoleId equals data2.RoleId join data3 in menu on data2.MenuId equals data3.MenuId where data1.UserId.Equals ("01") select new {UserId = data1.UserId, MenuId = data2.MenuId, Menu = data3,} Linq.Distinct () .OrderBy (I = > i.Menu.OrderNumber) .ToList () .ForEach (I = > Console.WriteLine ("user ID: {0}, menu ID {1}, menu name: {2}", i.UserId, i.MenuId, i.Menu.MenuName); Console.ReadKey ();}} # region entity object class User_Role {public string UserId {get; set;} public int RoleId {get; set } public User_Role (string userId, int roleId) {this.RoleId = roleId; this.UserId = userId;}} class Menu {public int MenuId {get; set;} public string MenuName {get; set;} public int OrderNumber {get; set;} public Menu (int menuId, string menuName, int orderNumber) {this.MenuId = menuId; this.MenuName = menuName; this.OrderNumber = orderNumber;} class Role_Menu {public int RoleId {get; set;} public int MenuId } public Role_Menu (int roleId, int menuId) {this.RoleId = roleId; this.MenuId = menuId;}} # endregion
The above is how to manage user rights in sqlserver. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.