.net core Mongodb 多表关联查询

江湖百晓生7个月前 (02-28)Mongodb630
var menus = new MongoDbHelper<Entitys.Menus>().ListAllAsync();
            MongoDbHelper<RoleForMenuAuthority> rfma = new();
            var rtnlist = new List<MenusRoleAuthorityView>();
            var list = from t1 in menus.Result
                       join t2 in rfma.ListAllAsync().Result.FindAll(r => r.RoleId.Equals(roleid))
                       on t1.Cid equals t2.MenuId
                       into rl
                       from r in rl.DefaultIfEmpty()
                       select new MenusRoleAuthorityView
                       {
                           Cid = t1.Cid,
                           MenuName = t1.MenuName,
                           Authority = (r == null ? 0 : r.Authority)
                       };
            foreach (var l in list)
            {
                var tmpentity = new MenusRoleAuthorityView
                {
                    Cid = l.Cid,
                    Authority = l.Authority,
                    MenuName = l.MenuName,
                };
                rtnlist.Add(tmpentity);
            }
            return rtnlist;


发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。