.net core Mongodb 多表关联查询

 2024-02-26 01:45:05      999    0 

var menus = new MongoDbHelper().ListAllAsync();
MongoDbHelper rfma = new();
var rtnlist = new List();
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;