1

I have this query:

public IEnumerable<TimesheetModel> 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
                 where workLogList.AccountId == id
                 group workLogList by workLogList.WorkDate into data
                 select new TimesheetModel
                 {
                     TaskDate = data.Key,
                     TimesheetList = data.Select(x => new TimesheetListModel()
                     {
                         ProjectId = x.tblTicket.tblProject.ProjectId,
                         ProjectName = x.tblTicket.tblProject.Name,
                         TaskDate = x.WorkDate,
                         TimeWorked = x.TimeWorked,
                         Note = x.Note,
                         Task = TaskString(x.tblTicket.TicketId, x.tblTicket.Title, x.TaskTitle)
                     }
                     ).ToList()
                 });
    return query.ToList();
}

In this line I need to use left join, because I also need to take data with worklogList.TicketId == null

join tickets in DataContext.tblTickets on workLogList.TicketId equals tickets.TicketId

How to use left join in this context?

HUSTLIN
  • 196
  • 4
  • 17

1 Answers1

1

if you just make the associations in the model, then remember to set cardinality to 0..1 - *.

Then you should be able to use the dot syntax and not join in the linq statement.

Added Later:

Here is the example that I would like you to end out with after having made those associations (untested ofcourse):

(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
             where workLogList.AccountId == id
             group workLogList by workLogList.WorkDate into data
             select new TimesheetModel
             {
                 TaskDate = data.Key,
                 TimesheetList = data.Select(x => new TimesheetListModel()
                 {
                     ProjectId = x.tblTicket.tblProject.ProjectId,
                     ProjectName = x.tblTicket.tblProject.Name,
                     TaskDate = x.WorkDate,
                     TimeWorked = x.TimeWorked,
                     Note = x.Note,
                     Task = TaskString(x.tblTicket.TicketId, x.tblTicket.Title, x.TaskTitle)
                 }
                 ).ToList()
             });
Thomas Koelle
  • 3,416
  • 2
  • 23
  • 44