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?

0

1 Answer 1

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()
             });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.