c# - Join two tables sortby user click count then everyone click count using linq -
c# - Join two tables sortby user click count then everyone click count using linq -
i'm new linq , need join. have 2 tables pages want bring together linq like
userfavorites table:
page.id userclickcount
page table:
id everyoneclickcount
a user favorite created when it's clicked or made favorite there amount of links. want show results both tables, sort them clicked user, clicked everyone.
i have right sorts count.
pages = (from page in context.page bring together ps in (from favs in context.userfavorites select favs) on page.id equals ps.page.id temp t in temp.defaultifempty() orderby t.userclickcount descending, t.page.everyoneclickcount descending, t.page.pagename ascending select dash).tolist();
i'm not sure go here.
try this:
var pages = context.pages.select(page => new { pagedata = page, favs = page.userfavorites }) .orderbydescending(page => (page.fav.sum(userclickcount)) .thenby(page => page.pagedata.everyoneclickcount) .thenby(page => page.pagedata.name) .tolist();
note order sum of all users' click counts. if want current user, replace line .orderbydescending(page => (page.fav.where(u => u.userid == userid).sum(userclickcount))
c# linq join favorites
Comments
Post a Comment