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
Post a Comment