linq/EF 使用技巧笔记

先上图

 

1、linq列转行(如图从上到下,action_type即power字段),其实严格意义上来说,并不是linq,只是用了循环

List<NavigationDto> leaf = new List<NavigationDto>();
            //列出所有操作权限
            managerList.Where(t => t.action_type.Length > 0).ForEach(
                a => a.action_type.Split(',').ForEach((t) => leaf.Add(new NavigationDto {
                    id = a.id+"_"+ t,
                    parent_id=a.id,
                    name = t,
                    title =t
                })));

2、linq行转列 (如图从下到上,action_type即power字段)

var actPower = leafPower.GroupBy(t => t.navigation_id).Select(
                t => new dt_manager_role_value() { navigation_id = t.Key, role_id = RoleID,
                    action_type = string.Join(",",t.Select(p=>p.action_type))});

  

 参照网址:https://www.cnblogs.com/zq281660880/archive/2012/09/26/2704836.html

posted @ 2018-12-16 22:30  南东  阅读(798)  评论(0编辑  收藏  举报