I have this code that shows all tickets with its reply info (if any) and it is working fine. The problem is when there is no reply for ticket found in ticket reply, the whole ticket info row from support ticket doesn't appear. So I want to show all rows in (Support_Teckets table) whether or not it has related data in the (Ticket_Reply table)
var query = (from st in Db.Support_Teckets
join rp in Db.Ticket_Reply.GroupBy(m => m.Support_Tecket_Id)
.Select(m => m.OrderByDescending(x => x.Date).FirstOrDefault())
on st.Support_Tecket_Id equals rp.Support_Tecket_Id
into g
from rp in g.DefaultIfEmpty()
join tr in Db.trainers on rp.trainer_id equals tr.trainer_id
join pr in Db.Technical_problem on st.Technical_problem_Id equals pr.Technical_problem_Id
select new SupportTicketsDetails
{
Support_Tecket_Id = st.Support_Tecket_Id,
Created_Date = st.Created_Date,
Created_Time = st.Created_Time,
Order_by = Db.trainers.Where(b => b.trainer_id == st.trainer_id)
.FirstOrDefault().trainer_name,
Technical_problem_name = pr.Technical_problem_name,
Created_details = st.Created_details,
Location = st.Location,
Technician = Db.trainers.Where(b => b.trainer_id == st.Technician_Id)
.FirstOrDefault().trainer_name,
Is_Closed = rp.Reply_Text,
Closing_Date = st.Closing_Date ,
Last_replier = Db.trainers.FirstOrDefault(a => a.trainer_id == rp.trainer_id)
.trainer_name.ToString(),
Last_reply_Date = rp.Date,
Last_reply_Time = rp.Time,
points = st.points
}).ToList().OrderByDescending(a => a.Created_Date);
return View(query);
I thank you for your cooperation in advance