I have sql query like below
select * from Attachments a left join UserTickets ut on ut.Id=a.UserTicketId left join Tickets t on t.Id=ut.TicketId where a.ItemKey='abcd'
its returning correct result in sql server, but when i am trying in linq to entities in my mvc project like below
var attachmentDetails = (from a in AttachmentsService.FindAllAttachments().Attachments join ut in UserTicketsService.FindAllUserTickets().UserTickets on a.UserTicketId equals ut.Id into aut from ut in aut.DefaultIfEmpty() join t in TicketsService.FindAllTickets().Tickets on ut.TicketId equals t.Id into utt from t in utt.DefaultIfEmpty() where a.ItemKey.ToUpper() == userName.ToUpper() select new UserTicketsViewModel { AttachmentId = a.Id, FilePath = a.FileName, TicketName=t!=null?t.TicketName:"", FileName = Path.GetFileName(a.FileName), UserId = UserId, }).ToList();
its give me exception at "ut.ticketId".inner excetion show "null".please suggest what i am doing wrong