c# - Linq group by and select -


i have *.cs model

public class timesheetlistmodel     {         public string projectname { get; set; }         public datetime taskdate { get; set; }         public string task { get; set; }         public decimal timeworked { get; set; }         public string note { get; set; }     } 

and have service, selects model database.

now need include model list<> new model:

 public class timesheetmodel     {         public datetime taskdate { get; set; }         public list<timesheetlistmodel> timesheetlist { get; set; }          public timesheetmodel() { timesheetlist = new list<timesheetlistmodel>(); }     } 

and need select data db new model, , group taskdate in new model. have service realize query, wrote old model:

public ienumerable<timesheetlistmodel> getticketsinprogressbyuserid(int id) {     var query = (from workloglist in datacontext.tblworklogs                  join tickets in datacontext.tbltickets on workloglist.ticketid equals tickets.ticketid                  join project in datacontext.tblprojects on tickets.projectid equals project.projectid                  join states  in datacontext.tblworkflowstates on tickets.status equals states.stateid                  workloglist.accountid == id                  select new timesheetlistmodel                  {                      projectname = project.name,                      taskdate = workloglist.workdate,                      task = "#" + tickets.ticketid + " : " +  tickets.title,                      timeworked = workloglist.timeworked,                      note = workloglist.note                  });     return query.tolist(); } 

how need rewrite query selecting data new model?

you can this:-

where workloglist.accountid == id group workloglist workloglist.workdate g select new timesheetmodel       {           taskdate = g.key,           timesheetlist = g.tolist()       }); 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -