2017-09-14 105 views
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(); 
+0

请以可读的方式格式化你的代码。提示:缩进4个空格。实际上问题或问题是什么? –

+0

问题或问题是什么? –

+0

** into **从查询体中获取错误必须以LINQ查询中的select子句或group子句结束 –

回答

1

您需要使用Where扩展方法的第一个查询,如查询使用左连接与DefaultIfEmpty(完注意,您可以” T选用intowhere条款,因为where必须遵循与select完成查询):

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(); 

类似的问题:

LINQ LEFT JOIN where clause not working

LINQ Left Join And Right Join

+0

谢谢你为我工作 –

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 
           };