.net - Sum and Group By in Linq to Entities -
i'm trying sum of values grouping , i'm stuck. sample structure of table:
what want is:
user name, project name, total work time of project users, grouped user name , project name.
the trick need display 0 or null value if user in project , user doesn't have work time yet.
example result should this:
username project total time user1 project1 15 user1 project2 -- user2 project1 10
how can accomplish this?
this scary select work, once add references (navigational properties)
db.users.selectmany( x=> x.projects .select(i=> new { user = x.name, project = i.name, worktime = (int?)i.userworktimes.sum(t=>t.worktime) }) );
my assumptions are
worktime of int type.
nav.property projects projectuserworktimes called userworktimes
nav.property users projects called projects
Comments
Post a Comment