c# - How to flatten tables using LINQ -


i've query:

var usersbybranch = (from u in _db.vrt_user                              join urb in _db.vrt_userrolebranch on u.userid equals urb.userid                              join r in _db.vrt_role on urb.roleid equals r.roleid                              branches.contains(urb.branchid)                              select new userrolebranchmodel                              {                                  userid = u.userid,                                  branchid = urb.branchid,                                  roleid = urb.roleid,                                  rolename = r.rolename                              }); 

in query, same userid, roleid (1-4) , rolename same branchid returned separately.

i'd flatten rows, row same userid contains roleid , rolename within same branchid.

your appreciated.

not sure mean contains, can't use same userrolebranchmodel hold multiple roles, anonymous object job:

var usersbybranch = (from u in _db.vrt_user                      join urb in _db.vrt_userrolebranch on u.userid equals urb.userid                      join r in _db.vrt_role on urb.roleid equals r.roleid                      branches.contains(urb.branchid)                      group r new { urb.userid, urb.branchid } rg                      select new {                          userid = rg.key.userid,                          branchid = rg.key.branchid,                          roles = rg.select(r => r)                      }); 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -