0
model.ListManagerReviewerMapping = (from a in wallet.OM_Employee 
                                    join m in wallet.APPR_ManagerMapping 
                                    on a.AssociateId equals m.AssociateId
                                    where m.ManagerId==Context.UserId.Value **into** MM 
                                    from leftjoinresult in M.DefaultIfEmpty() 
                                    where a.CompanyId == Context.CompanyId && (a.TermStatus == "L" || a.SeparationDate > DateTime.Today) 
                                    select new ManagerAndReviewerMappingModel.ManagerAndReviewerMapping() 
                                    { 
                                        Photo = (photoUrl + "?AssociateCode=" + a.AssociateCode), 
                                        AssociateId = a.AssociateId,
                                        AssociateCode = a.AssociateCode,
                                        AssociateName = a.AssociateName
                                    }).ToList();
Tetsuya Yamamoto
  • 24,297
  • 8
  • 39
  • 61

2 Answers2

1
//Remove brackets and .ToList();
model.ListManagerReviewerMapping = from a in wallet.OM_Employee 
                                join m in wallet.APPR_ManagerMapping 
                                on a.AssociateId equals m.AssociateId
                                where m.ManagerId==Context.UserId.Value **into** MM 
                                from leftjoinresult in M.DefaultIfEmpty() 
                                where a.CompanyId == Context.CompanyId && (a.TermStatus == "L" || a.SeparationDate > DateTime.Today) 
                                select new ManagerAndReviewerMappingModel.ManagerAndReviewerMapping() 
                                { 
                                    Photo = (photoUrl + "?AssociateCode=" + a.AssociateCode), 
                                    AssociateId = a.AssociateId,
                                    AssociateCode = a.AssociateCode,
                                    AssociateName = a.AssociateName
                                };
Manfice
  • 149
  • 7
1

You need to use Where extension method for first query, as the query uses left join with DefaultIfEmpty (note that you can't use into after where clause since where must be followed with select to finish the query):

model.ListManagerReviewerMapping = (from a in wallet.OM_Employee 
                                    join m in wallet.APPR_ManagerMapping.Where(x => x.ManagerId == Context.UserId.Value)
                                    on a.AssociateId equals m.AssociateId into MM 

                                    from leftjoinresult in MM.DefaultIfEmpty() 
                                    where a.CompanyId == Context.CompanyId && (a.TermStatus == "L" || a.SeparationDate > DateTime.Today) 
                                    select new ManagerAndReviewerMappingModel.ManagerAndReviewerMapping() 
                                    { 
                                        Photo = (photoUrl + "?AssociateCode=" + a.AssociateCode), 
                                        AssociateId = a.AssociateId,
                                        AssociateCode = a.AssociateCode,
                                        AssociateName = a.AssociateName
                                    }).ToList();

Similar issues:

LINQ LEFT JOIN where clause not working

LINQ Left Join And Right Join

Tetsuya Yamamoto
  • 24,297
  • 8
  • 39
  • 61